美文网首页
TypeError: 'newline' is an inval

TypeError: 'newline' is an inval

作者: KardelShaw | 来源:发表于2017-09-21 23:04 被阅读0次

下面是一个使用glob读取多个文本文件的代码,在mac终端运行后报错

//text.py

inputPath = sys.argv[1]
for input_file in glob.glob(os.path.join(inputPath, '*.txt')):
    with open(input_file, 'r', newline='') as filereader:
        for row in filereader:
            print(row.strip())

是因为输出python是调用mac自带的python,它的版本是2.7.10,它不支持newline


改用python3运行正常

相关文章

网友评论

      本文标题:TypeError: 'newline' is an inval

      本文链接:https://www.haomeiwen.com/subject/dbfxextx.html