Found 10476 Articles for Python

Python Low-level threading API

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

647 Views

The '_thread' module in Python library provides a low-level interface for working with light-weight 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()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 the thread. The thread ... Read More

Python interface for SQLite databases

George John
Updated on 30-Jul-2019 22:30:24

366 Views

SQLite is an open source database and is serverless that needs no configuration. Entire database is a single disk file that can be placed anywhere in operating system's file system. SQLite commands are similar to standard SQL. SQLite is extensively used by applications such as browsers for internal data storage. It is also convenient data storage for embedded devices.Standard Python library has in built support for SQLite database connectivity. It contains sqlite3 module which is a DB-API V2 compliant module written by Gerhad Haring. It adheres to DB-API 2.0.The DB-API has been defined in accordance with PEP-249 to ensure similarity ... Read More

Low-level networking interface in Python (socket)

Chandu yadav
Updated on 30-Jul-2019 22:30:24

1K+ Views

The 'socket' module in Python's standard library defines how server and client machines can communicate using socket endpoints on top of the operating system. The 'socket' API contains functions for both connection-oriented and connectionless network protocols.Socket is an end-point of a two-way communication link. It is characterized by IP address and the port number. Proper configuration of sockets on either ends is necessary so as to initiate a connection. This makes it possible to listen to incoming messages and then send the responses in a client-server environment.The socket() function in 'socket' module sets up a socket object.import socket obj = ... Read More

Python bootstrapping the pip installer

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

678 Views

In addition to the modules and packages built in to the standard distribution of Python, large number of packages from third party developers are uploaded to Python package repository called Python Package Index (https://pypi.org/. To install packages from here, pip utility is needed. The pip tool is an independent project, but since Python 3.4, it has been bootstrapped in Python distribution.The ensurepip module provides support for bootstrapping pip in existing installation of Python. Normally user doesn't need to use it explicitly. If however, installation of pip is skipped in normal installation or virtual environment, it may be needed.Following command will ... Read More

Data Classes in Python (dataclasses)

SaiKrishna Tavva
Updated on 17-Dec-2024 12:51:42

832 Views

In Python, the dataclasses module simplifies the creation of classes primarily used to store data. By using the @dataclass decorator, developers can automatically generate special methods such as __init__(), __repr__(), and __eq__(), which reduces boilerplate code and improves readability. Overview of dataclass Decorator The dataclass decorator has the following syntax: dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False) Each argument takes a boolean value, indicating whether corresponding special methods should be automatically generated: The @dataclass decorator can take these options: init (default: True): Automatically creates an __init__() ... Read More

Why is Python slower than other languages?

Dev Kumar
Updated on 26-Jun-2020 12:15:53

1K+ Views

Python is a scripting language while C is a programming language. C/C++ is relatively fast as compared to Python because when you run the Python script, its interpreter will interpret the script line by line and generate output but in C, the compiler will first compile it and generate an output which is optimized with respect to the hardware. In case of other languages such as Java and.NET, Java bytecode, and .NET bytecode respectively run faster than Python because a JIT compiler compiles bytecode to native code at runtime. CPython cannot have a JIT compiler because the dynamic nature of ... Read More

Disassembler for Python bytecode

Anvi Jain
Updated on 27-Jun-2020 14:24:11

3K+ Views

The dis module in Python standard library provides various functions useful for analysis of Python bytecode by disassembling it into a human-readable form. This helps to perform optimizations. Bytecode is a version-specific implementation detail of the interpreter.dis() functionThe function dis() generates disassembled representation of any Python code source i.e. module, class, method, function, or code object.>>> def hello(): print ("hello world") >>> import dis >>> dis.dis(hello) 2    0 LOAD_GLOBAL 0 (print)      3 LOAD_CONST 1 ('hello world')      6 CALL_FUNCTION 1 (1 positional, 0 keyword pair)      9 POP_TOP      10 LOAD_CONST 0 (None)      13 RETURN_VALUEBytecode ... Read More

Python Functions creating iterators for efficient looping

Nikitasha Shrivastava
Updated on 10-Jun-2025 19:01:35

272 Views

In this article, we will talk about creating iterators for efficient looping in Python functions. An iterator is something that helps you go through all the items one by one, like going through pages of a book one page at a time. In Python, we can use lists, tuples, dictionaries, and sets as iterators. So we will explore Python functions that generate iterators for efficient looping. Creating Iterators with Functions Python provides different ways to create iterators using functions. So let us see some examples of creating iterators for efficient looping in Python functions - Using Generator Functions Using ... Read More

Decimal fixed point and floating point arithmetic in Python

Nikitasha Shrivastava
Updated on 10-Jun-2025 19:07:53

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 incorrect because of how computers store them. 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 Arithmetic The following example will ... Read More

Random access to text lines in Python (linecache)

Chandu yadav
Updated on 25-Jun-2020 13:36:20

1K+ Views

Purpose of linecache module in Python’s standard library is to facilitate random access to any text file, although this module is extensively used by Python’s traceback module to generate error trace stack. Further prettyprints of reading are held in a cache so that it saves time while reading lines repeatedly.The most important function in this module is getline() which reads a specified line number from given file. Following is the list of functions −getline(file, x)This function returns xth line from file. If not present it will return empty string. If the file is not present in current path, function ties ... Read More

Advertisements