Python | os.device_encoding() method
Last Updated :
30 Oct, 2019
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.device_encoding()
method in Python is used to get the encoding of the device associated with the specified file descriptor, if it is connected to a terminal. This method returns None, if the specified file descriptor is not connected to a terminal.
Note: This method is available only on some flavour of UNIX.
Syntax: os.device_encoding(fd)
Parameter:
fd: A file descriptor, whose device encoding is to be queried.
Return Type: This method returns a string value which represents the encoding of the device associated with the specified file descriptor if it is connected to a terminal, otherwise None.
Code: Use of os.device_encoding() method to get the encoding of the device associated with the given file descriptor
import os
path = "/home/ihritik/Desktop/file.txt"
fd = os. open (path, os.O_RDWR | os.O_CREAT)
print ( "Connected to a terminal:" , os.isatty(fd))
print ( "Device encoding:" , os.device_encoding(fd))
master, slave = os.openpty()
print ( "Connected to a terminal:" , os.isatty(master))
print ( "Device encoding:" , os.device_encoding(master))
|
Output:
Connected to a terminal: False
Device encoding: None
Connected to a terminal: True
Device encoding: UTF-8
Share your thoughts in the comments
Please Login to comment...