Skip to content

FileIO.name property #9195

@FoamyGuy

Description

@FoamyGuy

I'm wondering how hard it would be to add support for the name property to FileIO (or wherever is appropriate for use with the built-in open())

Currently In CPython:

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open("something.txt", "wb")
>>> f.name
'something.txt'

Currently In CircuitPython:

Adafruit CircuitPython 9.1.0-beta.1-2-g87a400aa1d on 2024-04-21; Adafruit Feather ESP32-S3 TFT with ESP32S3
>>> f = open("boot_out.txt", "rb")
>>> f.name
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TextIOWrapper' object has no attribute 'name'

I noticed this difference between CPython and CircuitPython while working on a files argument for requests.post() In CPython that argument supports a type of value that would rely on retrieving the name of an already opened file. I was unable to find a way to do that with circuitpython, but if some way does already exist that could be used for my purpose and it wouldn't be strictly necessary to add support for name, but perhaps still nice to match cpython more closely.

If there is interest in this functionality, and if adding support for this wouldn't be super challenging I'd be willing to give it a try. But I would probably need a point in the right direction within the core code for where to start looking to add it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions