这个问题在这里已经有了答案: Equivalent of shell 'cd' command to change the working directory? (14 个回答) 3 年前关闭。
如何在 Python 中设置当前工作目录?
也许这就是您正在寻找的:
import os
os.chdir(default_path)
import os
print os.getcwd() # Prints the current working directory
设置工作目录:
os.chdir('c:\\Users\\uname\\desktop\\python') # Provide the new path here
\u
is 是语法错误;那应该是\\u
。
getcwd
).... 了不起。
它也适用于 Mac
import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)
检查工作目录
os.getcwd()
Python
python 的核心思想之一是跨平台工作。
"~/etc"
但没有成功。
~
,则需要使用 os.path.expanduser("~/etc")
,然后它将扩展为完整路径 (/path/to/homedir/etc
)
使用 pandas 包的人
import os
import pandas as pd
tar = os.chdir('<dir path only>') # do not mention file name here
print os.getcwd()# to print the path name in CLI
以下语法用于在 python CLI 中导入文件
dataset(*just a variable) = pd.read_csv('new.csv')
os.chdir
命令对 panda 的使用有所不同?
os.path.dirname(__file__)
不定期副业成功案例分享
os.getcwd()
,它显示了os.chdir()
接受的输入格式。