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'