"""For Translators: some useful info about the sentence below"""
_("Some string blah blah")
…您可以使用编译器模块可靠地解析Python文件:
>>> m = compiler.parseFile("f.py")
>>> m
Module('For Translators: some useful info about the sentence below', Stmt([Discard(CallFunc(Name('_'), [Const('Some string blah blah')], None, None))]))
f = """# For Translators: some useful info about the sentence below
_("Some string blah blah")
""".split("\n")
import re
for i, line in enumerate(f):
m = re.findall("\S*# (For Translators: .*)$", line)
if len(m) > 0 and i != len(f):
print "Line Number:", i+1
print "Message:", m
print "Line:", f[i + 1]
..输出:
Line Number: 1
Message: ['For Translators: some useful info about the sentence below']
Line: _("Some string blah blah")
在我大发雷霆之后,我找到了最好的办法:
然后使用搜索注释。是这样的:
^{pr2}$我本打算建议使用
compiler
模块,但它忽略了注释:f.py公司:
…以及编译器模块:
^{pr2}$python2.6中的AST模块似乎也是这样做的。在
不确定是否可行,但如果您使用三重引号字符串。。在
…您可以使用编译器模块可靠地解析Python文件:
我试图编写一个mode complete脚本来提取docstring—它是不完整的,但似乎抓住了大多数docstring:http://pastie.org/446156(或github.com/dbr/so_scripts)
另一种更简单的选择是使用正则表达式,例如:
..输出:
不确定
.pot
文件是如何生成的,因此我对该部分没有任何帮助。。在相关问题 更多 >
编程相关推荐