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

Alan G Isaac aisaac at american.edu
Thu Dec 4 20:50:58 CET 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