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.

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

# Close opened directory.

os.close( fd )

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

Current working dir : /var/www/html

Current working dir : /tmp

os.isatty(fd)

Description

The method isatty()returns True if the file descriptor fd is open and connected to a tty(-like) device, else False.

Syntax

Following is the syntax for isatty() method:

os.isatty( fd )

Parameters

• fd -- This is the file descriptor for which association needs to be checked.

Return Value

This method returns True if the file descriptor fd is open and connected to a tty(-like) device, else False.

Example

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

#!/usr/bin/python

import os, sys

# Open a file

fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )

# Write one string

os.write(fd, "This is test")

# Now use isatty() to check the file.

ret = os.isatty(fd)

print "Returned value is: ", ret

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!