tags:

views:

80

answers:

2

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?

+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
What is the r for? So I don't have to do \\ ?
devoured elysium
@devoured: Yes, the 'r' means "raw" string, a string literal without embedded escapes.
unwind
Yes, exactly that. It stands for a "raw string": http://docs.python.org/reference/lexical_analysis.html#string-literals
+3  A: 

Try os.path.basename().

unwind