Python os.getcwdu() Method
Python OS File/Directory Methods
Overview
The os.getcwdu() method is used to return a Unicode object of the current working directory.
Available on Unix and Windows systems.
Syntax
getcwdu()The method syntax format is as follows:
os.getcwdu()
Parameters
- None
Return Value
Returns a Unicode object of the current working directory.
Example
The following example demonstrates the use of the getcwdu() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# 切换到 "/var/www/html" 目录
os.chdir("/var/www/html" )
# 打印当前目录
print "当前工作目录 : %s" % os.getcwdu()
# 打开 "/tmp"
fd = os.open( "/tmp", os.O_RDONLY )
# 使用 os.fchdir() 方法修改目录
os.fchdir(fd)
# 打印当前目录
print "当前工作目录 : %s" % os.getcwdu()
# 关闭文件
os.close( fd )
The output of the above program is:
当前工作目录 : /var/www/html 当前工作目录 : /tmpOther Extensions