Python os.getcwdu() 方法



Python 方法os.getcwdu()返回一個unicode物件,表示當前工作目錄。

從Python 3.0版本開始,os.getcwdu()方法已棄用。可以使用os.getcwd()方法代替。

語法

Python os.getcwdu() 方法的語法如下:

os.getcwdu()

引數

Python os.getcwdu() 方法不接受任何引數。

返回值

Python os.getcwdu() 方法返回一個unicode物件,表示當前工作目錄。

示例

以下示例顯示了 getcwdu() 方法的用法。

#!/usr/bin/python

import os, sys

# First go to the "/var/www/html" directory
os.chdir("/var/www/html" )

# Print current working directory
print ("Current working dir : %s" % os.getcwdu())

# Now open a directory "/tmp"
fd = os.open( "/tmp", os.O_RDONLY )

# Use os.fchdir() method to change the dir
os.fchdir(fd)

# Print current working directory
print ("Current working dir : %s" % os.getcwdu())

# Close opened directory.
os.close( fd )

執行上述程式後,將產生以下結果:

Current working dir : /var/www/html
Current working dir : /tmp
python_files_io.htm
廣告
© . All rights reserved.