#os.mkdir(path) filename = '1.py' try: if not os.path.exists("Common"): os.mkdir("Common") else: if os.path.exists("Common/"+filename): print(filename) with io.open("Common/" + filename, 'r', encoding='utf8') as f: text = f.read() print(text) else: os.chdir("Common/") with io.open(filename, 'w', encoding='utf8') as f: f.write('涂聚文') with io.open("Common/" + filename, 'r', encoding='utf8') as f: text = f.read() print(text) except FileNotFoundError: print('文件不存在') except PermissionError: print('权限错误')
标签:encoding,python,text,create,filename,Common,file,print,os From: https://www.cnblogs.com/geovindu/p/18255407