Joe Halliwell
Joe Halliwell

Reputation: 1177

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?

Upvotes: 3

Views: 104

Answers (1)

Klaus D.
Klaus D.

Reputation: 14369

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.

Upvotes: 4

Related Questions