How do I handle #

M

Michael Sperlle

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.

Or is there something simpler? There must be.
 
I

Irmen de Jong

Michael said:
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:
'# some line with a hash comment\n'

--Irmen
 
F

Felipe Almeida Lessa

Em Sáb, 2006-03-25 às 00:46 +0000, Michael Sperlle escreveu:
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.

$ python
Python 2.3.5 (#2, Mar 6 2006, 10:12:24)
[GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.hi # hi

What's up?
 
F

Fredrik Lundh

Michael said:
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.

"turns into a comment" in what sense ? from your description, it sounds
like a bug in your editor's syntax highlighter. Python itself definitely won't
look for comment markers inside string literals.

</F>
 
M

Michael Sperlle

"turns into a comment" in what sense ? from your description, it sounds
like a bug in your editor's syntax highlighter. Python itself definitely
won't look for comment markers inside string literals.

Thanks, I just tried it again and it worked. I must have had a misplaced
bit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,291
Messages
2,571,453
Members
48,134
Latest member
JavierIlif

Latest Threads

Top