Server Side Programming Articles - Page 2627 of 2650

What are valid python identifiers?

Yaswanth Varma
Updated on 17-Jun-2025 17:34:18

954 Views

Identifiers are the names used to identify variables, functions, classes, and other objects. A valid identifier helps Python users to assign readable and meaningful names to the elements within the code. To be considered a valid identifier in Python must follow a specific set of rules. Rules For Valid Python Identifiers Following is a list of rules that are to be followed to consider as a valid identifier - The name must begin with the letter (A-Z or a-z) or an underscore. Identifiers cannot be keywords (like if, ... Read More

How do I find the location of Python module sources?

Manogna
Updated on 30-Sep-2019 09:02:50

12K+ Views

For a pure python module you can find the location of the source files by looking at the module.__file__. For example,  >>> import mymodule >>> mymodule.__file__ C:/Users/Ayush/mymodule.py  Many built in modules, however, are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, you can't see the source. You can manually go and check the PYTHONPATH variable contents to find the directories from where these built in modules are being imported.  Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to ... Read More

How do I unload (reload) a Python module?

Manogna
Updated on 30-Sep-2019 08:50:27

725 Views

The function reload(moduleName) reloads a previously loaded module (assuming you loaded it with the syntax "importmoduleName" without exiting the script. It is intended for conversational use, where you have edited the source file for a module and want to test it without leaving Python and starting it again. For example, >>> import mymodule >>> # Edited mymoduleand want to reload it in this script >>> reload(mymodule)Note that the moduleName is the actual name of the module, not a string containing its name. The python docs state following about reload function: Python modules’ code is recompiled and the module-level code re-executed, defining ... Read More

How to retrieve Python module path?

Yaswanth Varma
Updated on 17-Jun-2025 17:36:29

1K+ Views

In Python, every module exists in a specific file path within the file system. Sometimes, we need to find out where the module is located to perform different operations, like debugging or verifying the version of the module. In this article, we will explore how to retrieve the file path of a module. Retrieving Path of a Standard Library Module In this approach, we are going to import the built-in os module, which is part of the Python standard library, and use the 'os.__file__()' to get the absolute path to the actual ".py" or ".pyc" file where the ... Read More

What are the modules available in Python for converting PDF to text?

SaiKrishna Tavva
Updated on 07-Jan-2025 11:24:38

355 Views

Python offers several powerful libraries to convert PDF documents to plain text, such as PyPDF2 and PDFMiner which are two popular modules for text extraction from PDFs. Some of the common approaches (modules) for converting PDF to text are as follows- Using PyPDF2 Using PDFMiner Using PyMuPDF Using 'PyPDF2' Module PyPDF2 is a versatile library used for manipulating PDF files, focusing on functions such as merging, splitting, rotating pages, and extracting text. It offers a simple approach for performing basic PDF operations. To extract data using ... Read More

How to check version of python modules?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:53:00

5K+ Views

When you install Python, you also get the Python package manager, pip. You can use pip to get the versions of python modules. If you want to list all installed Python modules with their version numbers, use the following command:$ pip freezeYou will get the output:asn1crypto==0.22.0 astroid==1.5.2 attrs==16.3.0 Automat==0.5.0 backports.functools-lru-cache==1.3 cffi==1.10.0 ...To individually find the version number you can grep on this output on *NIX machines. For example:$ pip freeze | grep PyMySQL PyMySQL==0.7.11On windows, you can use findstr instead of grep. For example:PS C:\> pip freeze | findstr PyMySql PyMySQL==0.7.11If you want to know the version of a module ... Read More

How can I get a list of locally installed Python modules?

Yaswanth Varma
Updated on 28-Aug-2025 12:58:14

3K+ Views

Python is a flexible programming language that consists of thousands of libraries and libraries. As the Python environment grows with the installations, it is important to be able to check which packages are currently installed. Whether you are debugging or documenting the environment, listing locally installed python modules can be useful. In this article, we will explore the different ways to get a list of locally installed python modules using the built-in tools and external commands. Using pip list The pip is the Python package installer and the list is tje subcommand that shows all the installed ... Read More

What does reload() function do in Python?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:55:31

2K+ Views

The function reload(moduleName) reloads a previously loaded module (assuming you loaded it with the syntax "import moduleName". It is intended for conversational use, where you have edited the source file for a module and want to test it without leaving Python and starting it again. For example, >>> import mymodule >>> # Edited mymodule and want to reload it in this script >>> reload(mymodule)Note that the moduleName is the actual name of the module, not a string containing its name. In Python 3, reload was moved from builtins to imp. So to use reload in Python 3, you'd have to ... Read More

What is the difference between dir(), globals() and locals() functions in Python?

Yaswanth Varma
Updated on 17-Jun-2025 17:36:01

769 Views

The Python built-in functions,  dir(), globals(), and locals are used to provide insights into the objects, variables, and identifiers present in various scopes. They might look similar, but each function serves a different purpose and behaves differently depending on where and how it is used. In this article, we will discuss the difference between the dir(), globals(), and locals() in Python. Python dir() Function The Python dir() function is used to list the names in the current local scope or the attributes of an object. If no argument is passed, it returns the list of names ... Read More

What is a namespace in Python?

SaiKrishna Tavva
Updated on 17-Mar-2025 18:12:02

3K+ Views

A Namespace in Python is a container that holds a set of identifiers (variable names) and their associated objects (values). It helps implement the concept of scope in your program, determining which variables are accessible at any given point in your code. Every time a new scope is created—like when a function is defined or executed—a new namespace is created. This namespace acts as an "evaluation context" for the identifiers defined within it. Types of Namespaces Following are the three types of namespaces in Python. Local Namespace: Created for each function, method, or class block. ... Read More

Advertisements