473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1024
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Tony Johansson | last post by:
Hello!! Assume I have a handle body pattern with classes called Handle and Body. In the Body class I store one int value for example 7 or some other integer value. In the Handle class I have...
2
by: Indiana Epilepsy and Child Neurology | last post by:
Before asking this questions I've spent literally _years_ reading (Meyer, Stroustrup, Holub), googling, asking more general design questions, and just plain thinking about it. I am truly unable to...
14
by: Howard | last post by:
Hi, I recently had a problem where I decided to store objects in a vector. (Previously, I had always stored pointers in vectors). Well, naturally, when storing an object in a vector, using...
6
by: Leandro Berti via DotNetMonster.com | last post by:
Hi All, I wrote a code to do serial communication with an equipament. When i use the code outside of threaded class it seens work properly, but when i put inside a class and execute a thread in...
2
weaknessforcats
by: weaknessforcats | last post by:
Handle Classes Handle classes, also called Envelope or Cheshire Cat classes, are part of the Bridge design pattern. The objective of the Bridge pattern is to separate the abstraction from the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.