change some lines from a read file

MRAB google at mrabarnett.plus.com
Mon May 4 14:59:37 EDT 2009


utab wrote:
> Dear all,
> 
> I have to change some lines from a template file, which is rather long
> to paste here, but I would like to make some parts of some lines
> optional with my command line arguments but I could not see this
> directly, I can count the line numbers and decide on this basis to
> decide the lines to be configured to my will.
> 
> More specifically, say, I have a that file includes
> 
> this is an example python file to play around
> .
> .
> .
> some lines
> .
> .
> .
> . -> an option line for example.
> .
> .
> .
> -> another option line so on.
> 
> and execute the script
> ./myScript option1 option2
> 
> so that the options at correct locations will be written.
> 
> Any other options for this simple job that i can improve my Python a
> bit as well.
> 
You could put special markers around the optional parts in the template
file. Your script would remove the markers from around the optional
parts it wants to keep and then remove any remaining unwanted optional
parts and their markers.



More information about the Python-list mailing list