
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10400 Articles for Python

294 Views
The pyclbr module in Python library extracts information about the functions, classes, and methods defined in a Python module. The information is extracted from the Python source code rather than by importing the module.This module defines readmodule() function that return a dictionary mapping module-level class names to class descriptors. The function takes a module name as parameter. It may be the name of a module within a package. In that case path is a sequence of directory paths prepended to sys.path, which is used to locate the module source code.Following code uses readmodule() function to parse classes and methods in ... Read More

865 Views
Python is an interpreter based language. However it internally compiles the source code to byte code when a script (.py extension) is run and afterwards the bytecode version is automatically removed. When a module (apart from the precompiled built-in modules) is first imported, its compiled version is also automatically built but saved with .pyc extension in __pycache__ folder. Subsequent calls to import same module again won't recompile the module instead uses the one already built.However, a Python script file with .py extension can be compiled expilicitly without running it. The 'py_compile' module contains 'compile()' function for that purpose. Name of ... Read More

5K+ Views
Function in the 'trace' module in Python library generates trace of program execution, and annotated statement coverage. It also has functions to list functions called during run by generating caller relationships.Following two Python scripts are used as an example to demonstrate features of trace module.#myfunctions.py import math def area(x): a = math.pi*math.pow(x, 2) return a def factorial(x): if x==1: return 1 else: return x*factorial(x-1)#mymain.py import myfunctions def main(): x = 5 print ('area=', myfunctions.area(x)) ... Read More

618 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

350 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

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

637 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

765 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

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

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