描述
方法chdir()將當前工作目錄更改為給定路徑。在所有情況下都返回 None。
用法
以下是語法chdir()方法 -
os.chdir(path)
參數
path- 這是要更改到新位置的目錄的完整路徑。
返回值
此方法不返回任何值。它拋出FileNotFoundError如果沒有找到指定的路徑
示例
下麵的例子展示了 chdir() 方法的用法。
#!/usr/bin/python3
import os
path = "d:\\python3" #change path for linux
# Now change the directory
os.chdir( path )
# Check current working directory.
retval = os.getcwd()
print ("Directory changed successfully %s" % retval)
結果
當我們運行上述程序時,它會產生以下結果 -
Directory changed successfully d:\python3
相關用法
- Python 3 os.chflags()用法及代碼示例
- Python 3 os.chmod()用法及代碼示例
- Python 3 os.chroot()用法及代碼示例
- Python 3 os.chown()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.closerange()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.chdir() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。