Note two things: First off, I don't guarantee that it works well. Writing to files, if done wrong can always break things. Be careful. I mostly participate in this forum (the Python part) for fun, and my code is written like that.
Second: this script is about copying things. I mean it to be of use where you can work with code you find to help or be helped. Copying stuff always means copyright issues can come into play.
Okay...I am sure that there must be something like this around already, but I couldn't find it and it was quicker (and kind of fun) to write than to read/search endless sticky notes/code snippets and forum-clever-stuff.
Just in case someone else is lazy like me, I thought I would stick this little script up here.
I would have thought that something like this would have been on a page like http://www.daniweb.com/forums/misc-explaincode.html, but I didn't find it. If it is there, I am sorry, I'm on holiday :)
If you are trying to help someone, or getting help from someone and you copy the code posted in the thread and then paste it in your text editor, it puts the line numbers on one line and the code unchanged, with the right indentation on the next line.
A really simple script that opens your file, reads it, deletes each line with the line numbers and finally writes over your original file.
How to use it. If you are new to Python and the whole thing doesn't make sense to you right away, just copy a file to a location you want. Then in the
test = ClPyScps("/file/path", "filename.py") replace "file/path" with the, um, file path, and the filename.py with the file name, including the .py ending. You can, of course make this chopping automatic, but I was to lazy to figure that out when I wrote it. If you don't want to have the typical unix lines at the top, you can even get rid of the filepath and just give it all together (just be sure to change the __init__ method accordingly.)
If you want to watch the action in your command line - i.e. see what is being printed, add another parameter to the class initialization like this
test = ClPyScps("/path/to/test", "example.py", 1) That last little 1 will make it print what it is doing.
Then run if from a linux terminal:
vernon@mybox:~/Python/trying_stuff$ python cleanPyScripts.py
It can be improved by being able to pass the file path/file name with the command line. I'll do that later. It can be used with other code, not just Python, but needs to be tweeked accordingly.
Once again, if I am re-inventing the wheel...well...sorry. I just put it up here because I wrote it, found it useful, and thought someone else might also find it useful.