OS File 中的 os.getcwdu()函数

首页 / Python2入门教程 / OS File 中的 os.getcwdu()函数

Python方法getcwdu()返回表示当前工作目录的Unicode对象。

os.getcwdu() - 语法

os.getcwdu()

os.getcwdu() - 返回值

此方法返回表示当前工作目录的Unicode对象。

os.getcwdu() - 示例

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

#!/usr/bin/python

import os, sys

# 首先转到“/var/www/html”目录
os.chdir("/var/www/html" )

# 打印当前工作目录
print "Current working dir : %s" % os.getcwdu()

# 现在打开一个目录“/tmp”
fd=os.open( "/tmp", os.O_RDONLY )

# 使用OS.FCHDIR()方法更改DIR
os.fchdir(fd)

# 打印当前工作目录
print "Current working dir : %s" % os.getcwdu()

# 关闭已打开的目录。
os.close( fd )

当无涯教程运行上面的程序时,它产生以下输出-

Current working dir : /var/www/html
Current working dir : /tmp

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

软件测试52讲 -〔茹炳晟〕

白话法律42讲 -〔周甲徳〕

Linux实战技能100讲 -〔尹会生〕

Kafka核心源码解读 -〔胡夕〕

Redis核心技术与实战 -〔蒋德钧〕

深入浅出分布式技术原理 -〔陈现麟〕

说透元宇宙 -〔方军〕

Vue 3 企业级项目实战课 -〔杨文坚〕

互联网人的数字化企业生存指南 -〔沈欣〕

好记忆不如烂笔头。留下您的足迹吧 :)