TypeError: 'newline' is an invalid keyword argument for this function

下面是一个使用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 invalid keyword argument for this function_第1张图片

你可能感兴趣的:(TypeError: 'newline' is an invalid keyword argument for this function)