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.

Return Value

This method does not return any value.

Example

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

#!/usr/bin/python

# Open a file

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

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

# 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

file.flush()

Description

The method flush() flushes the internal buffer, like stdio's fflush. This may be a no-op on some file-like objects.

Python automatically flushes the files when closing them. But you may want to flush the data before closing any

file.

Syntax

Following is the syntax for flush() method:

fileObject.flush();

Parameters

• NA

Return Value

This method does not return any value.

Example

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

#!/usr/bin/python

# Open a file

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

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

# Here it does nothing, but you can call it with read operation.

fo.flush()

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!