如何从python源代码中删除评论和文档字符串? [英] How can I strip comments and doc strings from python source code?
本文介绍了如何从python源代码中删除评论和文档字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一个程序,我可以这样运行:
Is there a program which I can run like this:
py2py.py < orig.py > smaller.py
其中,orig.py包含带有注释和doc字符串的python源代码,包含相同的,可运行的源代码,但没有注释和文档字符串?
Where orig.py contains python source code with comments and doc strings, and smaller.py contains identical, runnable source code but without the comments and doc strings?
代码原来如下:
#/usr/bin/python
"""Do something
blah blah...
"""
# Beware the frubnitz!
def foo(it):
"""Foo it!"""
print it # hmm?
会如下所示:
def foo(it):
print it
推荐答案
这个Python minifier 看起来像你需要的。
这篇关于如何从python源代码中删除评论和文档字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文