我希望python脚本使用~作为主目录的快捷方式(因此我可以在几台具有不同主目录名的计算机上使用该脚本),将其转换为一个新目录:
os.chdir('~/google_drive/2014-11-05-QiimeAnalysis/quality_filtering/)然而,这会产生一个错误。Python似乎无法识别~:
FileNotFoundError: [Errno 2] No such file or directory: '~/google_drive/2014-11-05-QiimeAnalysis/quality_filtering/'为什么会发生这种情况,有什么办法可以绕过吗?我在OsX Yosemite上有python3.4。
发布于 2014-11-10 19:12:24
您必须使用os.path.expanduser将~扩展为实际路径:
os.chdir(os.path.expanduser('~/google_drive/2014-11-05-QiimeAnalysis/quality_filtering/'))https://stackoverflow.com/questions/26851045
复制相似问题