Home > Backend Development > Python Tutorial > How to modify the python directory (example analysis)

How to modify the python directory (example analysis)

乌拉乌拉~
Release: 2018-08-17 17:54:23
Original
1808 people have browsed it

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")
Copy after login

Example:

The following example will enter the "/home/newdir" directory.

# !/usr/bin/python
# -*- coding: UTF-8 -*-
import os
# 将当前目录改为"/home/newdir"
os.chdir("/home/newdir")
Copy after login

getcwd() method:

getcwd() method displays the current working directory.

Syntax:

os.getcwd()
Copy after login

Example:

The following example gives the current directory:

# !/usr/bin/python
# -*- coding: UTF-8 -*-
import os
# 给出当前的目录
print os.getcwd()
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template