In this article today, we will learn about python os.chdir. In the next article, we will introduce os.chdir() in python and introduce it. Definition and its functions and uses.
Overview
The os.chdir() method is used to change the current working directory to the specified path.
Grammar
chdir() method syntax format is as follows:
os.chdir(path)
Parameters
path – the new path to switch to.
Return value
Returns True if access is allowed, otherwise returns False.
Example
The following example demonstrates the use of the chdir() method:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys path = "/tmp" # 查看当前工作目录 retval = os.getcwd() print "当前工作目录为 %s" % retval # 修改当前工作目录 os.chdir( path ) # 查看修改后的工作目录 retval = os.getcwd() print "目录修改成功 %s" % retval
The output result of executing the above program is:
当前工作目录为 /www 目录修改成功 /tmp
The above is all the content of this article. I hope what I said and the examples I gave can be helpful to you.
For more related knowledge, please visit the Python tutorial column on the php Chinese website.
The above is the detailed content of python os.chdir() definition and function analysis (example analysis). For more information, please follow other related articles on the PHP Chinese website!