doubling slashes in a string

Steve Holden sholden at holdenweb.com
Mon Oct 9 12:23:58 EDT 2000


Alex Martelli wrote:
> 
> "Remco Gerlich" <scarblac at pino.selwerd.nl> wrote in message
> news:slrn8u3i4t.fgl.scarblac at pino.selwerd.nl...
...
> > Note that if he's doing things with pathnames on Windows, it might
> > be a lot easier to use / instead of \ to start with (that works).
> 
> I think the original poster explained that he needs to prepare a
> string to be passed to another program (dunno if by system, popen,
> or what else), so he *cannot* assume that / will work just the
> same as \ (on the commandline of many DOS and Windows programs,
> the equivalence does not hold).  I guess the doubling is what he
> needs to protect the backslashes from one level of stripping
> (whoever may be doing that...).
> 
> Alex

As always, the standard advice is to use the os.path module both
to construct and deconstruct pathnames, since this handles architectural
differences correctly in a platform-independent way!

I've had trouble fully understanding raw string literals.  Since

>>> len(r'\t')
2
>>> len(r'\"')
2
>>> len(r"\"")
2

can I assume

	a) There is no way to write a string literal containing
		only an apostrophe and a double-quote; and

	b) A string literal containing only a single backslash
		must be written as "\\"?

regards
 Steve
-- 
Helping people meet their information needs with training and technology.
703 967 0887      sholden at bellatlantic.net      http://www.holdenweb.com/



More information about the Python-list mailing list