V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
scalaview
V2EX  ›  Python

分离代码中的中英文,问题

  •  
  •   scalaview ·
    scalaview · 2013-03-26 09:48:07 +08:00 · 3443 次点击
    这是一个创建于 4048 天前的主题,其中的信息可能已经有所发展或是发生改变。
    今天写了一个代码中的中文抽取出来的小工具,已经把一些情况处理了,现在有点问题,想过来求帮助

    现在的代码有两种情况,有变量和没有变量的
    (1) alert("是否花费100赠送?")
    (2)alert("是否花费"+money+"赠送"+present)
    money和present都是变量
    第一种情况我是先用正则表达式匹配双引号,然后整个判断是否有中文然后决定是否抽取出来,结果是
    alert(msg_module_001),把中文写入xml里面
    第二种我希望第二种写入xml的结果是:是否花费{0}赠送{1},在代码的结果是alert(msg_module_001,money,present),


    求大神思路

    for l in open("FlowerPresentPanel.as"):
    li = l
    for g in re.findall(r'\"([^"]+)\"', l):
    full_str=""
    for s in split_zh_en(unicode(g, 'utf-8')):
    if s[0] == mark["en"]:
    full_str+='"'+s[1]+'"+'
    else :
    xml_key=prifix+str(index)
    xml.append('\t<string key="'+xml_key+'">')
    xml.append(s[1].decode('utf-8'))
    xml.append('</string>\n')
    full_str+=class_name+'.getLocalLang("'+xml_key+'")+'
    index+=1
    li=li.replace('"'+g+'"', full_str[0: len(full_str)-1])
    tme_str+=li
    1 条回复    1970-01-01 08:00:00 +08:00
    scalaview
        1
    scalaview  
    OP
       2013-03-26 10:32:22 +08:00
    怎么没人的,是不是信息不足
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3672 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 10:37 · PVG 18:37 · LAX 03:37 · JFK 06:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.