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.

Description

The method isatty() returns True if the file is connected (is associated with a terminal device) to a tty(-like) device,

else False.

Syntax

Following is the syntax for isatty() method:

fileObject.isatty();

Parameters

• NA

Return Value

This method returns true if the file is connected (is associated with a terminal device) to a tty(-like) device, else

false.

Example

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

#!/usr/bin/python

# Open a file

fo = open("foo.txt", "wb")

print "Name of the file: ", fo.name

ret = fo.isatty()

print "Return value : ", ret

# Close opened file

fo.close()

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

Name of the file: foo.txt

Return value : False

file.next()

Description

The method next() is used when a file is used as an iterator, typically in a loop, the next() method is called

repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit.

Combining next() method with other file methods like readline() does not work right. However, usingseek() to

reposition the file to an absolute position will flush the read-ahead buffer.

Syntax

Following is the syntax for next() method:

fileObject.next();

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!