Some of the tips, techniques and code freely imparted here, I’ve searched the web previously and come back empty handed. Then set about hand crafting my own solutions – which you get completely for free!.
If you have found my website useful, please consider buying me a coffee below 😉
One of the first things you are probably going to want to do is use modules.
For example to print out pi, we use the math module as below
import math math.pi
When we import modules they generally come with same namespace, i.e. calling pi function with prefix namespace of math. For performance, etc we can also just import the specific functions we want to use. This puts the function in the global name space. For example:
from math import pi pi
It is also possible to use a alias – such as
import math as m m.pi
You can also create your own modules simply by storing functions in filenames with .py extension. So for example we create a file called mymodule.py with following content
# mymodule.py def double(number): —>return 2 * number
Then we invoke with following .. if you get an error try import sys;print sys.path for folders searched for modules. Also you can use PYTHONPATH system variable to include other paths