Python方法getcwdu()返回表示当前工作目录的Unicode对象。
os.getcwdu()
此方法返回表示当前工作目录的Unicode对象。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/os-getcwdu.html
来源:LearnFk无涯教程网
以下示例显示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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)