如何设置当前工作目录? [重复]

本文介绍了在Python中如何更改或设置当前工作目录,适用于Unix和Windows系统。提供了相关代码示例,并提及该操作在使用pandas包时的场景。
摘要由CSDN通过智能技术生成

本文翻译自:How to set the current working directory? [duplicate]

This question already has an answer here: 这个问题在这里已有答案:

How to set the current working directory in Python? 如何在Python中设置当前工作目录?


#1楼

参考:https://stackoom.com/question/7b3X/如何设置当前工作目录-重复


#2楼

Try os.chdir 尝试os.chdir

 os.chdir(path) 

Change the current working directory to path. 将当前工作目录更改为路径。 Availability: Unix, Windows. 可用性:Unix,Windows。


#3楼

Perhaps this is what you are looking for: 也许这就是你要找的东西:

import os
os.chdir(default_path)

#4楼

import os
print os.getcwd()  # Prints the current working directory

To set the working directory: 要设置工作目录:

os.chdir('c:\\Users\\uname\\desktop\\python')  # Provide the new path here

#5楼

people using pandas package 人们使用熊猫包

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

the following syntax to be used to import the file in python CLI 以下语法用于在python CLI中导入文件

dataset(*just a variable) = pd.read_csv('new.csv')

#6楼

It work for Mac also 它也适用于Mac

import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)

To check working directory 检查工作目录

os.getcwd()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值