Latest web development tutorials

Python3 os.getcwdu () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.getcwdu () method returns a Unicode objects current working directory.

Unix, Windows system available.

grammar

getcwdu () method syntax is as follows:

os.getcwdu()

parameter

  • no

return value

Returns a Unicode objects current working directory.

Examples

The following example demonstrates getcwdu () method of use:

#!/usr/bin/python3

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 above program output is:

当前工作目录 : /var/www/html
当前工作目录 : /tmp

Python3 OS file / directory methods Python3 OS file / directory methods