Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do all file-like objects in the Python standard library have a `name` attribute?

Basic file objects have a name attribute i.e.

>>> open("/dev/null").name
'/dev/null'

Do all other file-like types (e.g. GzipFile) in the standard library have this attribute?

like image 575
Joe Halliwell Avatar asked May 14 '26 21:05

Joe Halliwell


1 Answers

No, for example a StringIO is a file-like object without name attribute. Most objects that are associated to an actual file have it, but it is not guaranteed.

like image 132
Klaus D. Avatar answered May 17 '26 12:05

Klaus D.