simplest way to strip a comment from the end of a line?

Alan G Isaac aisaac at american.edu
Thu Dec 4 14:50:58 EST 2008


rdmurray at bitdance.com wrote:
>     >>> from shlex import split
>     >>> split("this is a test #with a comment")
>     ['this', 'is', 'a', 'test', '#with', 'a', 'comment']
>     >>> split("this is a test #with a comment", comments=True)
>     ['this', 'is', 'a', 'test']
>     >>> split("this is a '#gnarlier' test #with a comment", comments=True)
>     ['this', 'is', 'a', '#gnarlier', 'test']
> 
> http://docs.python.org/library/shlex.html


It would be nice to have this example
included in the module docs...

Alan Isaac



More information about the Python-list mailing list