I want to turn C:\abc.bmp into abc.bmp, or even better, if possible, in abc. That is easy to do with .NET as there are functions for both goals. Is there anything similar in python?
views:
80answers:
2
+10
A:
>>> os.path.basename(r'C:\abc.txt')
'abc.txt'
for basename only:
>>> base, ext = os.path.splitext(os.path.basename(r'C:\abc.txt'))
>>> base
'abc'
SilentGhost
2009-12-14 10:59:47
What is the r for? So I don't have to do \\ ?
devoured elysium
2009-12-14 11:15:08
@devoured: Yes, the 'r' means "raw" string, a string literal without embedded escapes.
unwind
2009-12-14 11:54:27
Yes, exactly that. It stands for a "raw string": http://docs.python.org/reference/lexical_analysis.html#string-literals
2009-12-14 11:55:06