在用python上下文管理器打开文件时,编译器报错OSError: [Errno 22] Invalid argument:
检查发现
file_path = 'D:\python project\python_review\text_files\data.txt'
中\text_files中\t编译器理解成了转义字符
解决方案:在路径前加一个r
file_path = r'D:\python project\python_review\text_files\data.txt' with open(file_path) as file_object:
这样这个问题就解决啦