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
Write mode option for fileinput module. #44329
Comments
The current implementation of the fileinput module allows an optional 'mode' keyword argumant to the FileInput initializer and the input() convenience function. The attached patch provides a similar write_mode keyword argument with which to specify the write mode when the 'inplace' option is used. Included in the patch file are:
|
The restriction that you cannot use inplace and openhook together seems somewhat |
The restriction isn't entirely arbitrary as far as I can see. If you allow the combination of inplace and openhook, then you will also need a writehook option, or the ability to specify a pair of hook function for the openhook. For example, there is a function provided for opening a compressed file for reading. In order to do an inplace edit, you would need to provide a write hook to compress the data on the way back in. I think that the implementation of such a change would be open for discussion, and is beyond the scope of a minor change as suggested in this patch. (Perhaps the topic for a future PEP). |
This looks like a sizeable patch but the bulk of the changes are to test_fileinput.py. Assigning to myself to take forward, I've got to start sometime. Before I really start moving are there any basic objections to either the original proposal or me having a bash? |
As far as I can see from a quick look, the problem this patch addresses still exists in Python3, and in Python3 it be (more of?) a bug. That is, the output file is opened in text mode, regardless of whether the input mode was text or bytes. I'm not sure about the solution; it seems like it makes more sense to deduce the output mode from the input mode. The test changes, though, are obsolete. |
New changeset be6dbfb by Berker Peksag in branch 'master': |
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: