Python: get file name from filepointer

If I have a file pointer, is it possible to get the file name?

fp = open("C:\hello.txt") 

Is it possible to get hello.txt using fp?

+52
python
Mar 05 '13 at 13:54 on
source share
1 answer

Yes. You will receive it through fp.name . Example:

 >>> f = open('data.py') >>> f.name 'data.py' 

Docs file here

+73
Mar 05 '13 at 13:55 on
source share



All Articles