[Tutor] How can I escape a pound symbol in my script?

John Fouhy john at fouhy.net
Fri Jul 6 06:53:41 CEST 2007


On 06/07/07, Richard Querin <rfquerin at gmail.com> wrote:
> I'm writing a very simple python script which writes out some
> predefined text to a file (which will later become part of an html
> file). I need to write out a pound sign '#' to the file and I can't
> figure out how to escape it. I've tried '\#' and '\u0023', but neither
> works. How can I do it?

Why do you need to?  # doesn't mean anything special inside a quoted string.

>>> s = "# foo"
>>> print s
# foo


More information about the Tutor mailing list