jjzjj

PosixPath

全部标签

python - 使用 pathlib 时,出现错误 : TypeError: invalid file: PosixPath ('example.txt' )

我正在使用Python3的pathlib模块,像这样:frompathlibimportPathfilename=Path(__file__).parent/"example.txt"contents=open(filename,"r").read()但我在某些机器上收到此错误:TypeError:invalidfile:PosixPath('example.txt')但在我的机器上它可以工作。 最佳答案 pathlib仅在Python3.6及更高版本中与open无缝集成。来自Python3.6'sreleasenotes:Theb

python - 使用 pathlib 时,出现错误 : TypeError: invalid file: PosixPath ('example.txt' )

我正在使用Python3的pathlib模块,像这样:frompathlibimportPathfilename=Path(__file__).parent/"example.txt"contents=open(filename,"r").read()但我在某些机器上收到此错误:TypeError:invalidfile:PosixPath('example.txt')但在我的机器上它可以工作。 最佳答案 pathlib仅在Python3.6及更高版本中与open无缝集成。来自Python3.6'sreleasenotes:Theb