New submission from Zhiming Wang:

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])

----------
components: Library (Lib)
messages: 300860
nosy: zmwangx
priority: normal
severity: normal
status: open
title: fileinput inplace does not work with pathlib.Path
type: behavior
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue31281>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to