the slash & Windows paths

Juan Declet-Barreto Juan.Declet-Barreto at MesaAZ.gov
Mon Dec 19 17:02:50 EST 2011


All,

I have a Windows-style path that I need to modify so Python functions can find it. For example, the path "C:\Projects\Population_Pyramids\charts\test.xls" is being interpreted as pointing to a file called "est.xls" since the "t" is being escaped by the preceding slash as a tab.

I know this is straightforward to handle using raw literals by prefixing the literal with an 'r', but my path is stored in a variable.

My questions are: 1. How do I prevent single slashes from being escaped in a string variable (NOT literal)?
                                      2. Is it possible to do a string.replace to substitute all instances of '\' for '\\'? I tried this but it did not give me the desired result.

Juan Declet-Barreto [cid:image004.png at 01CCBE5F.46845530]
GIS Specialist, Information Technology Dept.
City of Mesa
Office: 480.644.4751
juan.declet-barreto at mesaaz.gov<mailto:juan.declet-barreto at mesaaz.gov>

[cid:image003.png at 01CCBE5E.C7AA1EC0]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111219/7464b515/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 11402 bytes
Desc: image003.png
URL: <http://mail.python.org/pipermail/python-list/attachments/20111219/7464b515/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 1454 bytes
Desc: image004.png
URL: <http://mail.python.org/pipermail/python-list/attachments/20111219/7464b515/attachment-0001.png>


More information about the Python-list mailing list