Found 10538 Articles for Python

What does reload() function do in Python?

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

1K+ 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 a namespace in Python?

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

2K+ 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

936 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

How to set your python path on Linux?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:45:28

932 Views

To set the PYTHONPATH on Linux to point Python to look in other directories for the module and package imports, export the PYTHONPATH variable as follows:$ export PYTHONPATH=${PYTHONPATH}:${HOME}/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 it will only bring you trouble.

How to set python environment variable PYTHONPATH on Windows?

Rajendra Dharmkar
Updated on 02-May-2023 12:43:46

43K+ Views

On Windows, you can set the PYTHONPATH environment variable to specify the directories that Python should search for modules when importing them. Here are several ways to set the PYTHONPATH environment variable on Windows Set PYTHONPATH using Command Prompt You can set the PYTHONPATH environment variable using Command Prompt by entering the following command − $set PYTHONPATH=c:\path\to\my\modules This sets the PYTHONPATH environment variable to c:\path\to\my\modules. To make this change permanent, you need to add it to the system environment variables − Open the Start menu and search for "Environment Variables". Click on "Edit the system environment variables". Click on ... Read More

How to set python environment variable PYTHONPATH on Mac?

Rajendra Dharmkar
Updated on 02-May-2023 12:42:27

12K+ Views

To set the Python environment variable PYTHONPATH on a Mac, you can follow these steps − Open the Terminal app on your Mac. Navigate to your home directory by typing cd ~ and pressing Enter. Open the .bash_profile file in a text editor by typing open -e .bash_profile and pressing Enter. Create a new file called .bash profile by typing touch .bash_profile and pressing Enter. Add a line to set the PYTHONPATH environment variable in the file. For example − $export PYTHONPATH=/path/to/my/python/ This sets the PYTHONPATH environment variable to the path /path/to/my/python/modules. You should replace this with the path to the directory where your Python modules are ... Read More

How to set Python environment variable PYTHONPATH on Linux?

Rajendra Dharmkar
Updated on 02-May-2023 12:39:55

23K+ Views

To set the PYTHONPATH environment variable on Linux, follow these steps − Open a terminal window on your Linux system. Determine the path to your Python module or package. For example, suppose you have a Python module named mymodule located in the /home/user/myproject folder. Set the PYTHONPATH environment variable to the path of your module or package using the following command − $export PYTHONPATH=/home/user/myproject:$ This command sets the PYTHONPATH environment variable to /home/user/myproject and also includes the previous value of PYTHONPATH in case it was already set. Note that the path should be separated by a colon (:) on Linux. Verify that the PYTHONPATH environment variable has been set correctly using the following command − ... Read More

What is PYTHONPATH environment variable in Python?

Rajendra Dharmkar
Updated on 26-Aug-2023 08:50:16

43K+ Views

In Python, PYTHONPATH is an environment variable that specifies a list of directories to search for Python modules when importing them. When you import a module in Python, Python looks for the module in the directories specified in sys.path, which is a list of directories that includes the current working directory and directories specified in PYTHONPATH. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find ... Read More

What is the use of "from...import *" Statement in Python?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:48:52

2K+ Views

The "from module import *" statement is used to import all function from a Python module. For example, if you want to import all functions from math module and do not want to prefix "math." while calling them, you can do it as follows:>>> from math import * >>> sin(0) 0.0 >>> cos(0) 1.0Note that for any reasonable large set of code, if you import * you will likely be cementing it into the module, unable to be removed. This is because it is difficult to determine what items used in the code are coming from 'module', making it easy ... Read More

Advertisements