Rajendra Dharmkar has Published 453 Articles

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

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Sep-2019 08:54:02

3K+ Views

There are multiple ways to get a list of locally installed Python modules. Easiest way is using the Python shell, for example, >>> help('modules') Please wait a moment while I gather a list of all available modules... BaseHTTPServer      brain_nose          markupbase         ... Read More

How to check version of python modules?

Rajendra Dharmkar

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 ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Sep-2019 08:49:27

1K+ Views

The "from module import function" statement is used to import a specific function from a Python module. For example, if you want to import the sin function from the math library without importing any other function, you can do it as follows:>>> from math import sin >>> sin(0) 0.0Note that ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

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

1K+ 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) ... Read More

How to set your python path on Linux?

Rajendra Dharmkar

Rajendra Dharmkar

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

743 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 ... Read More

How to set your python path on Mac?

Rajendra Dharmkar

Rajendra Dharmkar

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

1K+ 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 ... Read More

How to set your python path on Windows?

Rajendra Dharmkar

Rajendra Dharmkar

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

760 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 ... Read More

What is zfill() method in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Sep-2019 08:35:26

97 Views

The zfill method is built for left padding zeros in a string. For example:>>> '25'.zfill(6) '000025'We can also use the rjust(width[, fillchar]) method in string class that right justifies the string and pads the left side with given filler char. The default filler char is space but we can provide ... Read More

How to import a single function from a Python module?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Sep-2019 08:30:55

9K+ Views

You can use the "from module import function" statement to import a specific function from a Python module. For example, if you want to import the sin function from the math library without importing any other function, you can do it as follows:>>> from math import sin >>> sin(0) 0.0Note ... Read More

How to replace \\ with in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Sep-2019 08:23:04

582 Views

There are two ways to go about replacing \ with \ or unescaping backslash escaped strings in Python. First is using literal_eval to evaluate the string. Note that in this method you need to surround the string in another layer of quotes. For example:>>> import ast >>> a = '"Hello, ... Read More

Advertisements