28.10.2021 Views

Python Tutorial ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Description

The method ttyname() returns a string, which specifies the terminal device associated with fd. If fd is not

associated with a terminal device, an exception is raised.

Syntax

Following is the syntax for ttyname() method:

os.ttyname(fd)

Parameters

• fd -- This is the file descriptor.

Return Value

This method returns a string which specifies the terminal device.

Example

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

# !/usr/bin/python

import os, sys

# Showing current directory

print "Current working dir :%s" %os.getcwd()

# Changing dir to /dev/tty

fd = os.open("/dev/tty",os.O_RDONLY)

p = os.ttyname(fd)

print "the terminal device associated is: "

print p

print "done!!"

os.close(fd)

print "Closed the file successfully!!"

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

Current working dir is :/tmp

the terminal device associated is:

/dev/tty

done!!

Closed the file successfully!!

os.unlink(path)

Description

The method unlink() removes(delete) the file path. If the path is a directory, OSError is raised.

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!