Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to specify name to os.fdopen #44391

Closed
diekhans mannequin opened this issue Jan 1, 2007 · 9 comments
Closed

add ability to specify name to os.fdopen #44391

diekhans mannequin opened this issue Jan 1, 2007 · 9 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@diekhans
Copy link
Mannequin

diekhans mannequin commented Jan 1, 2007

BPO 1625576
Nosy @birkenfeld, @pitrou, @diekhans, @tiran, @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-02-10.11:58:03.971>
created_at = <Date 2007-01-01.07:19:56.000>
labels = ['type-feature', 'library']
title = 'add ability to specify name to os.fdopen'
updated_at = <Date 2015-02-10.11:58:03.969>
user = 'https://github.com/diekhans'

bugs.python.org fields:

activity = <Date 2015-02-10.11:58:03.969>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = True
closed_date = <Date 2015-02-10.11:58:03.971>
closer = 'serhiy.storchaka'
components = ['Library (Lib)']
creation = <Date 2007-01-01.07:19:56.000>
creator = 'diekhans'
dependencies = []
files = []
hgrepos = []
issue_num = 1625576
keywords = []
message_count = 9.0
messages = ['54958', '54959', '54960', '54961', '59356', '121026', '121027', '121047', '235683']
nosy_count = 6.0
nosy_names = ['georg.brandl', 'collinwinter', 'pitrou', 'diekhans', 'christian.heimes', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'test needed'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue1625576'
versions = ['Python 3.4']

@diekhans
Copy link
Mannequin Author

diekhans mannequin commented Jan 1, 2007

Please add an optional argument to os.fdopen() to specify the name field in
the resulting file object. This would allow
for a more useful name than:
<open file '<fdopen>'...>

@diekhans diekhans mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jan 1, 2007
@collinwinter
Copy link
Mannequin

collinwinter mannequin commented Mar 9, 2007

Changing this to a "feature request", since it's certainly not a bug.

I can see both sides of this; on the one hand, <fdopen> isn't the most descriptive string and doesn't give you an idea where it came from; on the other hand, you lose the distinction between files opened by filename and those by file descriptor.

If the purpose is to distinguish between fdopen()'d files, what if fdopen() was changed so that the filename matched <fdopen \d+>, where \d+ is the file descriptor passed to fdopen()?

@diekhans
Copy link
Mannequin Author

diekhans mannequin commented Mar 9, 2007

thanks collin; that was suppose to be a feature request!

<fdopen \d+> doesn't really help. For end user message, a file name is very use, the fact that it is opened by fdopen is not. If one is debugging a program and knows the file name, one can usually figure out where it is opened, the file number, or for that matter that fdopen was used is less useful.

The particular case that prompted this request was the need use os.open to get non-blocking mode and then pass the result to fdopen. However this now loses the file name, replacing it with something not useful.

thanks.

@diekhans
Copy link
Mannequin Author

diekhans mannequin commented Mar 9, 2007

p.s. I will happy implement the change.

@tiran
Copy link
Member

tiran commented Jan 6, 2008

Where is the patch, Mark?

Collin, does fdopen(fd[, mode[, bufsize[, msg=None]]]) and <open file
'<fdopen \d+ (msg)>'> sound good to you?

@collinwinter
Copy link
Mannequin

collinwinter mannequin commented Nov 12, 2010

Christian: yes, that sounds fine.

@collinwinter collinwinter mannequin unassigned collinwinter Nov 12, 2010
@birkenfeld
Copy link
Member

Collin: I doubt Christian will do much about this anymore :)

@pitrou
Copy link
Member

pitrou commented Nov 12, 2010

The requested feature would require an additional argument to fdopen() and open(), which already have many args. It would be better IMO to make the name attribute on file objects writeable.

By the way, right now (in 3.x) fdopen() gives you the file descriptor number, which is better than nothing:

>>> import os
>>> f = os.fdopen(2, "w")
>>> f
<_io.TextIOWrapper name=2 encoding='UTF-8'>

@tiran tiran added stale Stale PR or inactive for long period of time. labels Nov 17, 2013
@serhiy-storchaka
Copy link
Member

And the name attribute of FileIO object is writable. So you can change it after calling fdopen.

>>> import os
>>> f = os.fdopen(2, "w")
>>> f
<_io.TextIOWrapper name=2 mode='w' encoding='UTF-8'>
>>> f.buffer.raw.name = 'useful name'
>>> f
<_io.TextIOWrapper name='useful name' mode='w' encoding='UTF-8'>

@serhiy-storchaka serhiy-storchaka removed the stale Stale PR or inactive for long period of time. label Feb 10, 2015
@serhiy-storchaka serhiy-storchaka removed the stale Stale PR or inactive for long period of time. label Feb 10, 2015
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants