Python os.tmpnam() Method

Python File(文件) 方法Python OS File/Directory Methods


Overview

The os.tmpnam() method is used to return a unique path for creating a temporary file.

Syntax

tmpnam()The method syntax is as follows:

os.tmpnam

Parameters

  • None

Return Value

Returns a unique path.

Example

The following example demonstrates the use of the tmpnam() method:

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

import os, sys

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

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

The output of the above program is:

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

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions