如何从python源代码中删除注释和doc字符串?

6 python comments code-formatting

有没有我可以这样运行的程序:

py2py.py < orig.py > smaller.py
Run Code Online (Sandbox Code Playgroud)

其中orig.py包含带有注释和doc字符串的python源代码,而small.py包含相同的,可运行的源代码,但没有注释和doc字符串?

最初看起来像这样的代码:

#/usr/bin/python
"""Do something
blah blah...
"""

# Beware the frubnitz!
def foo(it):
    """Foo it!"""
    print it  # hmm?
Run Code Online (Sandbox Code Playgroud)

那么看起来像这样:

def foo(it):
    print it
Run Code Online (Sandbox Code Playgroud)

Bri*_*ell 8

这个Python缩小器看起来像它你需要的东西.