In today's article, we will learn about one aspect of directories in python. In this article, we will learn about how to change the directory name in python.
chdir() method
You can use the chdir() method to change the current directory. One parameter required by the chdir() method is the name of the directory you want to set as the current directory.
Syntax:
os.chdir("newdir")
Example:
The following example will enter the "/home/newdir" directory.
# !/usr/bin/python # -*- coding: UTF-8 -*- import os # 将当前目录改为"/home/newdir" os.chdir("/home/newdir")
getcwd() method:
getcwd() method displays the current working directory.
Syntax:
os.getcwd()
Example:
The following example gives the current directory:
# !/usr/bin/python # -*- coding: UTF-8 -*- import os # 给出当前的目录 print os.getcwd()
The above is all about the python directory in this article How to modify the directory name. 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 How to modify the python directory (example analysis). For more information, please follow other related articles on the PHP Chinese website!