Python os.tempnam() 方法

Python 教程 · 2019-02-04 12:44:50

概述

os.tempnam() 方法用于返回唯一的路径名用于创建临时文件。

语法

tempnam()方法语法格式如下:

os.tempnam(dir, prefix)

参数

  • dir -- 要创建的临时文件路径。

  • prefix -- 临时文件前缀

返回值

该方法返回唯一路径。

实例

以下实例演示了 tempnam() 方法的使用:

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

import os, sys

# 前缀为 codercto 的文件
tmpfn = os.tempnam('/tmp/codercto,'codercto')

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

执行以上程序输出结果为:

这是一个唯一路径:
/tmp/codercto/coderctoIbAco8

点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

PHP for the World Wide Web, Second Edition (Visual QuickStart Gu

Larry Ullman / Peachpit Press / 2004-02-02 / USD 29.99

So you know HTML, even JavaScript, but the idea of learning an actual programming language like PHP terrifies you? Well, stop quaking and get going with this easy task-based guide! Aimed at beginning ......一起来看看 《PHP for the World Wide Web, Second Edition (Visual QuickStart Gu》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具