Changes by Hanz Kanst bohemi...@gmail.com:
--
components: Windows
nosy: Hanz
priority: normal
severity: normal
status: open
title: os.path.split fails on windows path
type: behavior
versions: Python 3.3
___
Python tracker rep...@bugs.python.org
New submission from Hanz Kanst:
os.path.split fails on windows path
to reproduce in python 3.3:
file = C:\progs\python\test\target\Amy Winehouse\Amy Winehouse - Back To Black
(2006)\01 - Rehab.ogg
os.path.split(os.path.abspath(file))[0]
returns
'C:\\progs\\python\testordner\target\\Amy
Hanz Kanst added the comment:
According to the definition the tail should never contain a slash.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19844
___
SilentGhost added the comment:
file must be a raw string:
file = r'C:\progs\python'
Then everthing works.
--
nosy: +SilentGhost
resolution: - invalid
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19844
Christian Heimes added the comment:
Ah, you fell victim to a classic gotcha. :)
Either you have to quote \ with \\ or you have to use a raw string. Withouth a
raw string \t is TAB and \01 is the byte \x01:
import ntpath
fname = rC:\progs\python\test\target\Amy Winehouse\Amy Winehouse - Back
Hanz Kanst added the comment:
Hm, how can I handle this if file is an existing string and there is no
option to assign raw via r'some\raw\string'?
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19844
R. David Murray added the comment:
If it is an existing string, the backslashes are already in the string. The r
prefix or the escaping is only required to get the backslashes into a string
when you are coding them into a source file.
--
nosy: +r.david.murray