If I have a file pointer is it possible to get the filename?
fp = open("C:\hello.txt")
Is it possible to get "hello.txt" using fp?
You can get the path via fp.name. Example:
>>> f = open('foo/bar.txt')
>>> f.name
'foo/bar.txt'
You might need os.path.basename if you want only the file name:
>>> import os
>>> f = open('foo/bar.txt')
>>> os.path.basename(f.name)
'bar.txt'
File object docs (for Python 2) here.
filetype. - mgilsondir()on python objects to see what attributes are available. You'd have foundnameeasily that way. :-) - Martijn Pieters♦help(fp), which gives you all of the docs for the file type and its methods and data. - Eryk Sunos.path.basenamein the answer which would be irrelevant on the other question. - Mark Amery