69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

Python os.getcwdu() 方法

python os.getcwdu() 方法

python os 文件/目錄方法python os 文件/目錄方法

os.getcwdu() 方法用于返回一個(gè)當(dāng)前工作目錄的unicode對(duì)象。

unix, windows 系統(tǒng)下可用。

 

語(yǔ)法

getcwdu()方法語(yǔ)法格式如下:

os.getcwdu()

 

參數(shù)

  • 無(wú)

 

返回值

返回一個(gè)當(dāng)前工作目錄的unicode對(duì)象。

 

實(shí)例

以下實(shí)例演示了 getcwdu() 方法的使用:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, sys
# 切換到 "/var/www/html" 目錄
os.chdir("/var/www/html" )
# 打印當(dāng)前目錄
print "當(dāng)前工作目錄 : %s" % os.getcwdu()
# 打開(kāi) "/tmp"
fd = os.open( "/tmp", os.o_rdonly )
# 使用 os.fchdir() 方法修改目錄
os.fchdir(fd)
# 打印當(dāng)前目錄
print "當(dāng)前工作目錄 : %s" % os.getcwdu()
# 關(guān)閉文件
os.close( fd )

執(zhí)行以上程序輸出結(jié)果為:

當(dāng)前工作目錄 : /var/www/html
當(dāng)前工作目錄 : /tmp

python os 文件/目錄方法python os 文件/目錄方法

下一節(jié):python os.isatty() 方法

python 教程

相關(guān)文章
Python基礎(chǔ)