【发布时间】:2020-06-10 09:10:19
【问题描述】:
您好,我正在编写一个小脚本,它将为我制作一个网站模板。我将创建一个别名来运行脚本,这就是我遇到问题的原因。运行脚本时,我不想将目录写入要创建文件夹的位置。我希望它在我的 terminals 工作目录中创建。我如何 "os.chdir()" 到我的终端工作目录。 我试过了:
import os
dir_path = os.system("pwd | clip")
os.chdir(dir_path)
Output:
TypeError: chdir: path should be string, bytes or os.PathLike, not int
TL,DR 我想获取脚本在终端中执行的路径,然后 os.chdir() 到它
【问题讨论】:
标签: python terminal directory operating-system