Escaping slashes (double backslash plague)

Peter Hansen peter at engcorp.com
Mon Jan 19 14:52:59 EST 2004


Aloysio Figueiredo wrote:
> 
> I need to replace every ocurrence of '/' in s by '\/'
> in order to create a file named s. 

Harry inspired me to reread your question, but now I think you might 
be very confused about something.

Are you trying to create a file whose name contains a forward
slash?  And you think that by "escaping" the slash with a backslash,
you can do this?

If so, give up: it's not possible.  File names cannot contain a
forward slash, at least on most any operating system which uses slashes
as path separators. (*)

If this isn't what you're trying to do, please explain more thoroughly
what your goal is, because it seems very unnecessary to be putting 
\/ into a string for any reason (whether as a path or not) ...

-Peter

(*) Examples to the contrary, while perhaps interesting, notwithstanding...



More information about the Python-list mailing list