How to get the name of an open file?

One more useful trick to add. I agree with original correct answer, however if you’re like me came to this page wanting the filename only without the rest of the path, this works well.

>>> f = open('/tmp/generic.png','r')
>>> f.name
'/tmp/generic.png'
>>> import os
>>> os.path.basename(f.name)
'generic.png'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)