the slash & Windows paths

Andrew Berg bahamutzero8825 at gmail.com
Mon Dec 19 17:32:13 EST 2011


On 12/19/2011 4:02 PM, Juan Declet-Barreto wrote:
> 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.
Whatever code is getting the path and storing it into a variable needs
to escape the path. Otherwise, you'll have to replace each
tab/newline/etc. with literal \t/\n/\r/etc., and that's ugly and could
lead to problems (you may have special characters you want to keep). The
reason your replace code didn't work is because the \t is a tab
character, not a literal "\t". The replace function doesn't see "\t",
but rather a tab.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0



More information about the Python-list mailing list