Latest web development tutorials

méthode Python os.tmpnam ()

méthode Python Fichier (File) méthodes fichier / répertoire Python OS


contour

méthode os.tmpnam () est utilisée pour créer un fichier temporaire renvoie un chemin unique.

grammaire

tmpnam () Syntaxe de la méthode est la suivante:

os.tmpnam

Paramètres

  • aucun

Valeur de retour

Renvoie un chemin unique.

Exemples

L'exemple suivant illustre tmpnam () méthode d'utilisation:

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

import os, sys

# 生成临时路径
tmpfn = os.tmpnam()

print "这是一个唯一的路径:"
print tmpfn

La sortie du programme ci-dessus est:

这是一个唯一的路径:
/tmp/fileUFojpd

méthode Python Fichier (File) méthodes fichier / répertoire Python OS