Programming Articles

Page 613 of 2547

Python class browser support

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

The pyclbr module in Python's standard library extracts information about functions, classes, and methods defined in a Python module. The information is extracted from the Python source code rather than by importing the module, making it safe for analyzing potentially problematic code. readmodule() Function The readmodule() function returns a dictionary mapping module-level class names to class descriptors. It takes a module name as parameter and may include modules within packages ? import pyclbr mod = pyclbr.readmodule("socket") def show(c): s = "class " + c.name print(s + ...

Read More

Byte-compile Python libraries

Chandu yadav
Chandu yadav
Updated on 25-Mar-2026 997 Views

Python is an interpreter-based language that internally compiles source code to bytecode when a script is executed. While bytecode is automatically removed for scripts, imported modules create .pyc files in the __pycache__ folder for faster subsequent imports. You can also explicitly byte-compile Python files using the py_compile module. What is Byte Compilation? When Python imports a module, it automatically creates a compiled bytecode version with .pyc extension. This bytecode loads faster than parsing the original .py file. The py_compile module allows you to create these bytecode files manually without running or importing the code. Command Line Compilation ...

Read More

Trace or track Python statement execution (trace)

George John
George John
Updated on 25-Mar-2026 6K+ Views

The trace module in Python provides powerful tools for monitoring program execution, generating coverage reports, and tracking function calls. It helps developers debug code by showing which lines execute and how many times. Example Files Setup Let's create two Python files to demonstrate the trace module features ? myfunctions.py #myfunctions.py import math def area(x): a = math.pi * math.pow(x, 2) return a def factorial(x): if x == 1: return 1 ...

Read More

Python Low-level threading API

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

The _thread module in Python provides a low-level interface for working with lightweight processes having multiple threads sharing a global data space. For synchronization, simple locks (also called mutexes or binary semaphores) are defined in this module. The threading built-in module provides a higher-level threading API built on top of this module. start_new_thread() Function This module-level function is used to open a new thread in the current process. The function takes a function object as an argument. This function gets invoked on successful creation of the new thread. The span of this function corresponds to the lifespan of ...

Read More

Python bootstrapping the pip installer

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

The ensurepip module provides support for bootstrapping the pip installer in existing Python installations. While pip is included by default since Python 3.4, there are cases where you might need to install it manually using ensurepip. Why Use ensurepip? The ensurepip module is useful when: pip installation was skipped during Python installation You created a virtual environment without pip pip needs to be reinstalled or upgraded Creating Virtual Environment Without pip You can create a virtual environment that excludes pip using the --without-pip option ? python -m venv --without-pip testenv ...

Read More

Disassembler for Python bytecode

Anvi Jain
Anvi Jain
Updated on 25-Mar-2026 3K+ Views

The dis module in Python's standard library provides functions for analyzing Python bytecode by disassembling it into human-readable form. This helps with code optimization and understanding how Python executes your code internally. Basic Disassembly with dis() The dis() function generates a disassembled representation of Python code objects like functions, methods, or classes − import dis def hello(): print("hello world") dis.dis(hello) 2 0 LOAD_GLOBAL ...

Read More

Python Functions creating iterators for efficient looping

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 25-Mar-2026 358 Views

In this article, we will talk about creating iterators for efficient looping in Python functions. An iterator is an object that helps you go through all items one by one, like reading pages of a book sequentially. In Python, we can use lists, tuples, dictionaries, and sets as iterables. Let's explore Python functions that generate iterators for efficient looping and memory management. What are Iterators? An iterator is an object that implements the iterator protocol, consisting of __iter__() and __next__() methods. Iterators are memory-efficient because they generate values on demand rather than storing all values in memory ...

Read More

Decimal fixed point and floating point arithmetic in Python

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 25-Mar-2026 2K+ Views

This article will explain how decimal fixed-point and floating-point arithmetic work in Python, which is useful for performing accurate calculations in various applications. Numbers in Python can be stored in two ways: floating-point and decimal fixed-point. Floating-point numbers are fast but can sometimes be imprecise because of how computers store them in binary. On the other hand, Decimal fixed-point numbers are more accurate and useful when working with precise calculations. By the end of this article, you will understand how both types of numbers work, when to use them, and how to write programs using them. Floating-Point ...

Read More

Random access to text lines in Python (linecache)

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

The linecache module in Python's standard library provides random access to any text file by line number. This module is extensively used by Python's traceback system to generate error traces and caches previously read lines to improve performance when reading lines repeatedly. Key Functions getline(filename, lineno) Returns the specified line number from a file. If the line doesn't exist, it returns an empty string. If the file isn't in the current directory, it searches in sys.path. getlines(filename) Returns all lines from a file as a list object. clearcache() Clears the internal cache when ...

Read More

Iterate over lines from multiple input streams in Python

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

Python's built-in open() function handles single file operations, but when you need to process multiple files sequentially, the fileinput module provides a powerful solution. This module allows you to iterate over lines from multiple input streams as if they were a single continuous stream. Basic Usage with fileinput.input() The primary interface is the fileinput.input() function, which returns a FileInput object that can iterate over multiple files ? import fileinput # Reading from a single file for line in fileinput.input('data.txt'): print(line, end='') Processing Multiple Files You can pass multiple ...

Read More
Showing 6121–6130 of 25,466 articles
« Prev 1 611 612 613 614 615 2547 Next »
Advertisements