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
Comments
Please add an optional argument to os.fdopen() to specify the name field in |
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()? |
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. |
p.s. I will happy implement the change. |
Where is the patch, Mark? Collin, does fdopen(fd[, mode[, bufsize[, msg=None]]]) and <open file |
Christian: yes, that sounds fine. |
Collin: I doubt Christian will do much about this anymore :) |
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 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'> |
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'> |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: