Python3 os.chdir() 方法

Python 3 教程 · 2019-02-07 07:29:11

概述

os.chdir() 方法用于改变当前工作目录到指定的路径。

语法

chdir()方法语法格式如下:

os.chdir(path)

参数

  • path -- 要切换到的新路径。

返回值

如果允许访问返回 True , 否则返回False。

实例

以下实例演示了 chdir() 方法的使用:

#!/usr/bin/python3

import os, sys

path = "/tmp"

# 查看当前工作目录
retval = os.getcwd()
print ("当前工作目录为 %s" % retval)

# 修改当前工作目录
os.chdir( path )

# 查看修改后的工作目录
retval = os.getcwd()

print ("目录修改成功 %s" % retval)

执行以上程序输出结果为:

当前工作目录为 /www
目录修改成功 /tmp

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Programming the Mobile Web

Programming the Mobile Web

Maximiliano Firtman / O'Reilly Media / 2010-07-23 / $44.99

* Learn how to use your existing skills to move into mobile web development * Discover the new possibilities of mobile web development, and understand its limitations * Get detailed coverage of ......一起来看看 《Programming the Mobile Web》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试