Méthode os.getcwdu() de Python

Python File(文件) 方法Méthodes de fichier/répertoire du module OS de Python


Aperçu

La méthode os.getcwdu() est utilisée pour renvoyer un objet Unicode du répertoire de travail actuel.

Disponible sur les systèmes Unix et Windows.

Syntaxe

getcwdu()Le format de syntaxe de la méthode est le suivant :

os.getcwdu()

Parameters

  • Aucune

Valeur de retour

Renvoie un objet Unicode du répertoire de travail actuel.

Exemple

L'exemple suivant illustre l'utilisation de la méthode getcwdu() :

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os, sys

# 切换到 "/var/www/html" 目录
os.chdir("/var/www/html" )

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

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

# 使用 os.fchdir() 方法修改目录
os.fchdir(fd)

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

# 关闭文件
os.close( fd )

La sortie du programme ci-dessus est :

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

Python File(文件) 方法Méthodes de fichier/répertoire du module OS de Python

Autres extensions