How do I handle #
Irmen de Jong
irmen.NOSPAM at xs4all.nl
Fri Mar 24 19:55:23 EST 2006
Michael Sperlle wrote:
> I need to write out a file containing the # comment. When I try to specify
> it as part of a literal, everything afterward turns into a comment.
>
> I finally created a file containing the #, read it in, and used the
> resulting variable as part of the string I created.
>
> But that is so kludgy, even a newbie like me is ashamed to use it, though
> I did.
>
> Supposedly, I can us \x followed by the hex equivalent and somehow make
> that work.
>
> Can anybody give an example of this; my attempts failed.
Failed in what strange way?
I don't see a problem at all:
>>> open("bla.txt",'w').write("# some line with a hash comment\n")
>>> open("bla.txt").read()
'# some line with a hash comment\n'
--Irmen
More information about the Python-list
mailing list