Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue31281

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:fileinput inplace does not work with pathlib.Path
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.7, Python 3.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: eric.smithNosy List: eric.smith, zmwangx
Priority:normalKeywords:

Created on2017-08-26 01:50 byzmwangx, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 3208mergedzmwangx,2017-08-26 02:23
Messages (3)
msg300860 -(view)Author: Zhiming Wang (zmwangx)*Date: 2017-08-26 01:50
Consider    import fileinput    import pathlib    with fileinput.input(files=(pathlib.Path('in.txt'),), inplace=True) as fp:        for line in fp:            print(line, end='')which results in    Traceback (most recent call last):      File "./pathlib-fileinput.py", line 6, in <module>        for line in fp:      File "/Users/zmwang/.pyenv/versions/3.6.1/lib/python3.6/fileinput.py", line 250, in __next__        line = self._readline()      File "/Users/zmwang/.pyenv/versions/3.6.1/lib/python3.6/fileinput.py", line 331, in _readline        self._filename + (self._backup or ".bak"))    TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'A trivial fix is converting the specified filename to str when assigning to self._filename:    -        self._filename = self._files[0]    +        self._filename = str(self._files[0])
msg301231 -(view)Author: Eric V. Smith (eric.smith)*(Python committer)Date: 2017-09-04 17:37
New changeset06de1aeff94e524bed21d188065c4cd1590fb046 by ericvsmith (Zhiming Wang) in branch 'master':bpo-31281: Fix pathlib.Path incompatibility in fileinput (gh-3208)https://github.com/python/cpython/commit/06de1aeff94e524bed21d188065c4cd1590fb046
msg301237 -(view)Author: Eric V. Smith (eric.smith)*(Python committer)Date: 2017-09-04 18:15
I did not backport this to 3.6, because it depends on other changes that themselves have not been backported.
History
DateUserActionArgs
2022-04-11 14:58:51adminsetgithub: 75462
2017-09-04 18:15:28eric.smithsetstatus: open -> closed
versions: - Python 3.4, Python 3.5
messages: +msg301237

assignee:eric.smith
resolution: fixed
stage: resolved
2017-09-04 17:37:26eric.smithsetnosy: +eric.smith
messages: +msg301231
2017-08-26 02:23:00zmwangxsetpull_requests: +pull_request3245
2017-08-26 01:50:52zmwangxcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp