28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

import os

# The file has no directory entries associated with it and will be

# deleted automatically once there are no file descriptors.

tmpfile = os.tmpfile()

tmpfile.write('Temporary newfile is here.....')

tmpfile.seek(0)

print tmpfile.read()

tmpfile.close

Let us compile and run the above program, this will produce the following result:

Temporary newfile is here.....

os.tmpnam()

Description

The method tmpnam() returns a unique path name that is reasonable for creating a temporary file.

Syntax

Following is the syntax for tmpnam() method:

os.tmpnam()

Parameters

• NA

Return Value

This method returns a unique path name.

Example

The following example shows the usage of tmpnam() method.

# !/usr/bin/python

import os, sys

# Temporary file generated in current directory

tmpfn = os.tmpnam()

print "This is the unique path:"

print tmpfn

Let us compile and run the above program, this will produce the following result:

This is the unique path:

/tmp/fileUFojpd

os.ttyname(fd)

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!