>>> import sys >>> sys.path.append('/ufs/guido/lib/python') < / p >
在回答关于获取和设置当前目录的原始问题时:
>>> help(os.getcwd)
getcwd(...)
getcwd() -> path
Return a string representing the current working directory.
>>> help(os.chdir)
chdir(...)
chdir(path)
Change the current working directory to the specified path.
# Import the os package
import os
# Confirm the current working directory
os.getcwd()
# Use '\\' while changing the directory
os.chdir("C:\\user\\foldername")
import os
current_dir = os.path.dirname(os.path.abspath(__file__)) # Can also use os.getcwd()
print(current_dir) # prints(say)- D:\abc\def\ghi\jkl\mno"
new_dir = os.chdir('..\\..\\..\\')
print(new_dir) # prints "D:\abc\def\ghi"