469,352 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

How do I handle #

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.

Mar 25 '06 #1
4 941
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
Mar 25 '06 #2
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.
print "hi # hi" hi # hi print 'hi # hi' hi # hi print r"hi # hi" hi # hi print u"hi # hi"

hi # hi

What's up?

--
Felipe.

Mar 25 '06 #3
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.


"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>

Mar 25 '06 #4
On Sat, 25 Mar 2006 07:06:59 +0100, Fredrik Lundh wrote:
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.


"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.

Mar 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Tony Johansson | last post: by
2 posts views Thread by Indiana Epilepsy and Child Neurology | last post: by
14 posts views Thread by Howard | last post: by
6 posts views Thread by Leandro Berti via DotNetMonster.com | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.