python - Get characters of a string (from right) -
i'm looking best way file name of variable looks that:
= 'this\is\a\path\to\file' print a[-4:]
i'm trying 'file' extracting last 4 letters print a[-4:] result is:
ile
if make print a[-5:] get:
ofile
i guess python has problem backslash, escaping did not help. how solve this? way or there more performant way "file" searching '\' right left?
\f
single character (form-feed) in python. try doubling backslashes:
a = 'this\\is\\a\\path\\to\\file'
or, equivalently:
a = r'this\is\a\path\to\file'
after print a[-4:]
print file
.
Comments
Post a Comment