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.

Return Value

This method returns the number of bytes actually written.

Example

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

# !/usr/bin/python

import os, sys

# Open file

fd = os.open("f1.txt",os.O_RDWR|os.CREAT)

# Writing text

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

# ret consists of number of bytes written to f1.txt

print "the number of bytes written: "

print ret

print "written successfully"

# Close opened file

os.close(fd)

print "Closed the file successfully!!"

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

the number of bytes written:

12

written successfully

Closed the file successfully!!

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!