python3.8windows如何获得txt的绝对路径?
我用这个程序获得了一些路径,但不知道对不对。 class GetPath: def get_path(self,path): r=os.path.abspath(path) return r if __name__ == '__main__': a=GetPath().get_path(x) print(a)我的write总是无法写入文件:a = open('2.txt','w')a.write('111')a.close()
1、你对os.path.abspath理解有问题,它是得到某一路径的绝对路径用的,如当前目录".",与txt无关
2、你无法写入文件,要看具体报的错,如路径不可写等
上一篇:三维家怎么把隐藏的门恢复出来
热门标签: