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.

# Close opened file

os.close( fd )

print "Closed the file successfully!!"

This would create given file foo.txt and then would write given content in that file and would produce the following

result:

Closed the file successfully!!

os.openpty()

Description

The method openpty() opens a pseudo-terminal pair and returns a pair of file descriptors(master,slave) for the

pty & the tty respectively.

Syntax

Following is the syntax for openpty() method:

os.openpty()

Parameters

• NA

Return Value

This method returns a pair of file descriptors i.e., master and slave.

Example

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

# !/usr/bin/python

import os

# master for pty, slave for tty

m,s = os.openpty()

print m

print s

# showing terminal name

s = os.ttyname(s)

print m

print s

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

3

4

3

/dev/pty0

TUTORIALS POINT

Simply Easy Learning

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

Saved successfully!

Ooh no, something went wrong!