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.

os.read(fd,n)

Parameters

• fd -- This is the file descriptor of the file.

• n -- These are n bytes from file descriptor fd.

Return Value

This method returns a string containing the bytes read.

Example

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

# !/usr/bin/python

import os, sys

# Open a file

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

# Reading text

ret = os.read(fd,12)

print ret

# Close opened file

os.close(fd)

print "Closed the file successfully!!"

Let us compile and run the above program, this will print the contents of file f1.txt:

This is test

Closed the file successfully!!

os.readlink(path)

Description

The method readlink() returns a string representing the path to which the symbolic link points. It may return an

absolute or relative pathname.

Syntax

Following is the syntax for readlink() method:

os.readlink(path)

Parameters

• path -- This is the path or symblic link for which we are going to find source of the link.

Return Value

This method return a string representing the path to which the symbolic link points.

Example

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

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!