[Tutor] path

ingo ingo at ingoogni.nl
Sat Jun 29 10:33:44 EDT 2019


On 29-6-2019 15:52, Mats Wichmann wrote:
> Sigh... something dropped my raw string, so that was a really bad sample :(
> 
> inp = r"c:\test\drive\this"
> 
> 
> On Sat, Jun 29, 2019, at 07:44, Mats Wichmann wrote:
>>
>> For your example, when you define inp as a string, it needs to be a raw
>> string because otherwise Python will interpret the backslash sequences.
>> \t means tab, which is why the the results look mangled.
>>
>> inp = "c:\test\drive\this"
>>


import pathlib
print('input')
a=input()
b=r"{}".format(a) #does this make sense to create a r'string'?
wa = pathlib.PureWindowsPath(a)
wb = pathlib.PureWindowsPath(b)
pa = pathlib.PurePosixPath(a)
pb = pathlib.PurePosixPath(b)
ppa = pathlib.PurePosixPath(wa)
ppb = pathlib.PurePosixPath(wb)


input
c:\test\this\path\
>>> print(a)
c:\test\this\path\
>>> print(b)
c:\test\this\path\
>>> print(wa)
c:\test\this\path
>>> print(wb)
c:\test\this\path
>>> print(pa)
c:\test\this\path\
>>> print(pb)
c:\test\this\path\
>>> print(ppa)
c:\/test/this/path
>>> print(ppb)
c:\/test/this/path

What I'm looking for is c:/test/this/path


More information about the Tutor mailing list