현재 작업 디렉토리를 설정하는 방법은 무엇입니까?[복제하다]
-
05-07-2019 - |
문제
이 질문에는 이미 답변이 있습니다.
Python에서 현재 작업 디렉터리를 설정하는 방법은 무엇입니까?
해결책
노력하다 os.chdir
os.chdir(path)
현재 작업 디렉토리를 경로로 변경하십시오. 가용성 : Unix, Windows.
다른 팁
아마도 이것은 당신이 찾고있는 것입니다.
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
그것은 작동합니다 맥 또한
import os
path="/Users/HOME/Desktop/Addl Work/TimeSeries-Done"
os.chdir(path)
작업 디렉토리를 확인합니다
os.getcwd()
사용...
import os
os.chdir(path)
여기서 (경로)는 다음의 출력에 표시된 형식입니다.
os.getcwd()
팬더 패키지를 사용하는 사람들
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()
방법이지만 인용문을 사용하는 것을 잊지 마십시오 (''
) 괄호 안에 :
import os
os.chdir('default_path')
제휴하지 않습니다 StackOverflow