Reputation: 43
I found out a method called os.path.basename
to get the filename with extension. But even when I import os, I am not able to call it path.basename
. Is it possible to call it as directly as basename?
Upvotes: 0
Views: 42
Reputation: 4606
Having a little trouble understanding your problem at hand, just throwing some ideas out there
1
>>> import os
>>> name = os.path.basename('~/python/data.txt')
>>> name
'data.txt'
2
>>> from os import path
>>> name = path.basename('~/python/data.txt')
>>> name
'data.txt'
3
>>> from os.path import basename
>>> name = basename('~/python/data.txt')
>>> name
'data.txt'
Upvotes: 1
Reputation: 79
Is it you are looking for?
from os.path import basename
basename('~/test.txt')
Upvotes: 2