file_path =(r'i:\vacpy\ch10\pi_digits.txt') #将文件路径存储在变量file_path中with open (file_path) as file_object: contents = file_object.read() print(contents) """windows system 有时能够正确地解读文件路径中的斜杆.如果你使用的是windows system,且结果不符合预期,请确保文件路径中使用的是反斜杆.另外,由于反斜杆…
1.相对路径 windows '.\'表示当前路径 with open(r'.\db\123.txt','w',encoding='utf-8') as f: f.write('abc') 2.绝对路径 2.1 直接加死绝对路径 with open('c:\db\123.txt','w',encoding='utf-8') as f: f.write('abc') 2.2 动态绝对路径 import os,sys project_path = os.path.dirname(os.path.a…