如何在Python中设置当前工作目录?
当前回答
import os
print os.getcwd() # Prints the current working directory
设置工作目录。
os.chdir('c:\\Users\\uname\\desktop\\python') # Provide the new path here
其他回答
尝试os.chdir
进口操作系统 os.chdir(路径) 将当前工作目录更改为path。可用性:Unix, Windows。
人们使用熊猫包装
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')
它也适用于Mac
import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)
检查工作目录
os.getcwd()
也许这就是你想要的:
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
推荐文章
- 证书验证失败:无法获得本地颁发者证书
- 当使用pip3安装包时,“Python中的ssl模块不可用”
- 无法切换Python与pyenv
- Python if not == vs if !=
- 如何从scikit-learn决策树中提取决策规则?
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 将旋转的xtick标签与各自的xtick对齐
- 为什么元组可以包含可变项?
- 如何合并字典的字典?
- 如何创建类属性?
- 不区分大小写的“in”
- 在Python中获取迭代器中的元素个数
- 解析日期字符串并更改格式
- 使用try和。Python中的if
- 如何在Python中获得所有直接子目录