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.

os.tempnam(dir, prefix)

Parameters

• dir -- This is the dir where the temporary filename will be created.

• prefix -- This is the prefix of the generated temporary filename.

Return Value

This method returns a unique path.

Example

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

# !/usr/bin/python

import os, sys

# prefix is tuts1 of the generated file

tmpfn = os.tempnam('/tmp/tutorialsdir,'tuts1')

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/tutorialsdir/tuts1IbAco8

os.tmpfile()

Description

The method tmpfile() returns a new temporary file object opened in update mode (w+b). The file has no directory

entries associated with it and will be deleted automatically once there are no file descriptors.

Syntax

Following is the syntax for tmpfile() method:

os.tmpfile

Parameters

• NA

Return Value

This method returns a new temporary file object

Example

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

# !/usr/bin/python

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!