Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.getcwdu() method

Python os.getcwdu() method

Python File methods Python OS file/directory methods


Overview

The os.getcwdu() method returns a Unicode object of the current working directory.

Available on Unix and Windows systems.

Syntax

The syntax of the **getcwdu()** method is as follows:



os.getcwdu()

Parameters

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



# Switch to the "/var/www/html" directory

os.chdir("/var/www/html" )



# Print current directory

print "当前工作目录 : %s" % os.getcwdu()



# Open "/tmp"

fd = os.open( "/tmp", os.O_RDONLY )



# Change directory using os.fchdir() method

os.fchdir(fd)



# Print current directory

print "当前工作目录 : %s" % os.getcwdu()



# Close file

os.close( fd )

The output of the above program is:



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

当前工作目录 : /tmp

Python File methods Python OS file/directory methods