Programming Articles

Page 97 of 2547

Python Interface to UNIX syslog library routines

George John
George John
Updated on 25-Mar-2026 390 Views

The syslog module provides a Python interface to the UNIX system logging facility. It allows your Python programs to send messages to the system log, which administrators can monitor for debugging and system monitoring purposes. To use this module, we need to import it ? import syslog syslog.syslog() Method This method sends a string message to the system logger. You can specify a priority level for the message. Syntax syslog.syslog(message) syslog.syslog(priority, message) Parameters: message - String message to log priority - Optional priority level (LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, ...

Read More

How to access Python objects within objects in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 25-Mar-2026 243 Views

In Python, it's common to have objects within objects. To access objects within objects, you can use the dot notation. Let's take a look at an example. Example In this example, we have a `Person` class that contains an `Address` object. We create a `Person` object `p` with a name of "Alice" and an age of 25. The `Person` constructor also creates an `Address` object with the street address "123 Main St", the city "Anytown", and the country "USA". To access the street, city, and country properties of the Address object within the Person object, we use ...

Read More

Resource Usage Information using Python

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 1K+ Views

Python's resource module helps monitor and control system resource usage in UNIX-based systems. It provides methods to get resource usage statistics and set resource limits to prevent processes from consuming excessive system resources. Importing the Resource Module First, import the resource module ? import resource Resource Limits The module uses two types of limits: soft limits (current limit that can be changed) and hard limits (maximum value for soft limits). Soft limits cannot exceed hard limits, and hard limits can only be reduced. Method resource.getrlimit(resource) Returns the current soft and hard ...

Read More

Python Interface to Shell Pipelines

Ankith Reddy
Ankith Reddy
Updated on 25-Mar-2026 435 Views

The pipes module in Python provides an interface to shell command pipelines, allowing you to chain UNIX commands together. This module uses /bin/sh command line and works with os.system() and os.popen() methods internally. Note: The pipes module is deprecated as of Python 3.3 and removed in Python 3.11. For modern applications, consider using subprocess module instead. Importing the Module To use this module, import it as follows − import pipes Template Class The pipes module contains the Template class, which is an abstraction of a pipeline that allows you to build and ...

Read More

The fcntl and ioctl System Calls in Python

Arjun Thakur
Arjun Thakur
Updated on 25-Mar-2026 3K+ Views

The fcntl module in Python provides an interface to the fcntl() and ioctl() Unix system calls for file control operations. This module is essential for low-level file descriptor manipulation, file locking, and I/O control operations on Unix-like systems. All methods in this module take a file descriptor (integer) or io.IOBase object as their first argument. To use this module, import it first: import fcntl fcntl.fcntl(fd, op[, arg]) Method This method performs operations on file descriptors. The op parameter defines the operation, and the optional arg can be an integer or string. When arg is ...

Read More

POSIX Style TTY control using Python

Ankith Reddy
Ankith Reddy
Updated on 25-Mar-2026 624 Views

The termios module provides an interface to the POSIX calls for TTY I/O control. It is only available for Unix-based systems and allows you to control terminal behavior programmatically. Importing the Module To use the termios module, import it as follows − import termios All methods in this module take a file descriptor as an argument. The module provides several methods for controlling terminal attributes. Method termios.tcgetattr(fd) This method returns a list of TTY attributes for the given file descriptor. The attributes include: iflag − Input mode flags oflag − ...

Read More

How we can compress large Python files?

Niharika Aitam
Niharika Aitam
Updated on 25-Mar-2026 450 Views

Working with large files in Python can be challenging due to storage space and processing requirements. Python's zipfile module provides an effective solution for compressing files, reducing their size significantly while maintaining data integrity. Why Compress Files? File compression offers several benefits: Storage Efficiency − Reduces disk space usage Transfer Speed − Faster file uploads and downloads Memory Management − Lower memory consumption when handling files Archiving − Better organization of multiple files Basic Syntax The zipfile module provides a simple interface for creating compressed archives: import zipfile # Basic syntax zipfile.ZipFile(filename, mode, compression) Where: ...

Read More

The most Common POSIX System Calls in Python

Arjun Thakur
Arjun Thakur
Updated on 25-Mar-2026 1K+ Views

The posix module provides low-level UNIX system call functionality in Python. While you shouldn't import it directly, understanding its core functions helps you work with file descriptors and system operations through the os module. Overview The posix module works on UNIX environments and provides operating system functionality. Instead of importing posix directly, use the os module, which acts as a superset of posix on UNIX systems. On non-Unix systems, posix is not available, but os provides similar functionality with some limitations. posix.environ Constant The environ is a dictionary object containing environment variables. Keys and values are ...

Read More

Convenient Web-browser controller in Python

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 1K+ Views

To display web-based documents to users in Python, there is a module called webbrowser. It provides a high-level interface to handle web documents and control web browsers programmatically. On UNIX-based systems, this module supports lynx, Netscape, Mosaic and other browsers. For Windows and macOS, it uses the standard browsers. Importing the Module To use this module, we need to import it first ? import webbrowser Main Methods webbrowser.open(url, new=0, autoraise=True) This method opens the specified URL using the default web browser. The new parameter controls how the URL opens ? ...

Read More

Generate Secure Random Numbers for Managing Secrets using Python

Arjun Thakur
Arjun Thakur
Updated on 25-Mar-2026 489 Views

To generate secure random numbers cryptographically we can use the secrets module in Python. This module is helpful to create secure passwords, account authentication tokens, security tokens, and other cryptographic secrets. The secrets module provides access to the most secure source of randomness that your operating system provides, making it suitable for managing secrets where security is essential. Importing the Secrets Module To use the classes and functions of the secrets module, we need to import it into our code ? import secrets Random Number Generation Methods The secrets module provides several ...

Read More
Showing 961–970 of 25,469 articles
« Prev 1 95 96 97 98 99 2547 Next »
Advertisements