Server Side Programming Articles - Page 2624 of 2646

How do I unload (reload) a Python module?

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

740 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

384 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

807 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

How to set your python path on Windows?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:44:06

1K+ Views

To set the PYTHONPATH on windows to point Python to look in other directories for module and package imports, go to:My Computer > Properties > Advanced System Settings > Environment VariablesThen under system variables edit the PythonPath variable. At the end of the current PYTHONPATH, add a semicolon and then the directory you want to add to this path:C:\Python27;C:\fooIn this case, are adding the foo directory to the PYTHONPATH. Note that we are appending it and not replacing the PYTHONPATH's original value. In most cases, you shouldn't mess with PYTHONPATH. More often than not, you are doing it wrong and ... Read More

How to set your python path on Mac?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:44:46

2K+ Views

To set the PYTHONPATH on Mac OS to point Python to look in other directories for module and package imports, export the PYTHONPATH variable as follows:$ export PYTHONPATH=${PYTHONPATH}:${HOME}/foo In this case are adding the foo directory to the PYTHONPATH. Note that we are appending it and not replacing the PYTHONPATH's original value. In most cases, you shouldn't mess with PYTHONPATH. More often than not, you are doing it wrong and it will only bring you trouble

Advertisements