[Tutor] VERY newbie question
Remco Gerlich
scarblac@pino.selwerd.nl
Sat, 22 Jul 2000 21:35:31 +0200
On Fri, Jul 21, 2000 at 02:02:51PM -0700, Daniel Yoo wrote:
> The other one is obscure to new users; the backslash character, '\', is
> special in Python strings. It indicates a control ("escape") sequence.
> Some of these are useful; for example, "\n" means "skip to a new
> line". Try this out, and you'll understand:
>
> print "Hello, this is\non another\nline.\t\tThis is tabbed a bit."
>
> There are a few escape sequences. The example above uses '\n'
> (newline) and '\t' (tab). To tell Python not to see the backslash as an
> escape, you can trap it using "raw" string notation:
>
> r"C:\"
>
> Put an 'r' in front of your string quotes, and it should be ok.
Ah, but this is unfortunate, it still doesn't work. Since it should still
be possible to include " signs in a raw string, they are in fact escaped
(the \-es are left in the string). Printing r"\"" prints \".
So raw strings can never end in an odd number of backslashes... Newbies
shouldn't have to deal with this stuff.
"C:\\" Does work. So does r"C:\ " (with a space).
Also, you can use / inside a path. "C:/Program Files/etc" is a completely
legal Windows path, it can use both. It looks unusual though.
--
Remco Gerlich, scarblac@pino.selwerd.nl