How can I strip comments and doc strings from python source code? [closed]

2024/5/20 20:01:20

Is there a program which I can run like this:

py2py.py < orig.py > smaller.py

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?

Code which originally looked like this:

#/usr/bin/python
"""Do something
blah blah...
"""# Beware the frubnitz!
def foo(it):"""Foo it!"""print it  # hmm?

Would then look like this:

def foo(it):print it
Answer

This Python minifier looks like it does what you need.

https://en.xdnf.cn/q/73083.html

Related Q&A

How to install scipy misc package

I have installed (actually reinstalled) scipy:10_x86_64.whl (19.8MB): 19.8MB downloaded Installing collected packages: scipy Successfully installed scipyBut the misc subpackage is apparently not includ…

How to color surface with stronger contrast

In Matlab, I am trying to plot a function on 2-dim Euclidean space with following codes=.05; x=[-2:s:2+s]; y=[-1:s:3+s]; [X,Y]=meshgrid(x,y); Z=(1.-X).^2 + 100.*(Y-X.*X).^2; surf(X,Y,Z) colormap jetHer…

How to know that the interpreter is Jython or CPython in the code? [duplicate]

This question already has answers here:Can I detect if my code is running on cPython or Jython?(5 answers)Closed 9 years ago.Is there a way to detect that the interpreter that executes the code is Jyt…

Regular expression - replace all spaces in beginning of line with periods

I dont care if I achieve this through vim, sed, awk, python etc. I tried in all, could not get it done.For an input like this:top f1 f2 f3sub1 f1 f2 f3sub2 f1 f2 …

Writing append only gzipped log files in Python

I am building a service where I log plain text format logs from several sources (one file per source). I do not intend to rotate these logs as they must be around forever.To make these forever around f…

How to configure bokeh plot to have responsive width and fixed height

I use bokeh embedded via the components function. Acutally I use :plot.sizing_mode = "scale_width"Which scales according to the width and maintains the aspect ratio. But I would like to have …

Matplotlib show multiple images with for loop [duplicate]

This question already has an answer here:Can I generate and show a different image during each loop?(1 answer)Closed 8 years ago.I want to display multiple figure in Matplotlib. Heres my code:for i in…

How do I efficiently fill a file with null data from python?

I need to create files of arbitrary size that contain no data. The are potentially quite large. While I could just loop through and write a single null character until Ive reached the file size, that s…

Setting specific permission in amazon s3 boto bucket

I have a bucket called ben-bucket inside that bucket I have multiple files. I want to be able to set permissions for each file URL. Im not too sure but Im assuming if I wanted URL for each file inside …

Create new column in dataframe with match values from other dataframe

Have two dataframes, one has few information (df1) and other has all data (df2). What I am trying to create in a new column in df1 that finds the Total2 values and populates the new column accordingly…