Key Ideas
The key ideas for this part centre on importing and installing modules.
Importing
The safest form of import is:
import geostuff
point_1 = geostuff.GeoPoint()
If you're sure there are no other GeoPoints, you can:
from geostuff import GeoPoint
This just imports this one class.
point_1 = GeoPoint()
While you can import everything:
from geostuff import *
avoid it; you've no idea what you're importing.
If the module or classname is very long, you can:
import geostuffthatisuseful as geo
point_1 = geo.GeoPoint()
from useful import GeographicalPointForMaps as GP
point_1 = GP()
Avoiding code running on import
Generally, on import, loose code in modules and classes will run. Avoid this by placing all code in functions and use the following to isolate code to run if you want the module to also run as a script:
if __name__ == "__main__":
# Imports needed for running.
function_name()
Scripts
In general in scripts and modules code has to be defined before it can be used within the same module.
class A:
def b (__self__) :
print ("hello world")
c = A()
c.b()
External libraries
A very complete list of external packages can be found at the PyPi the Python Package Index
To install external libraries, use pip, which comes with Python:
pip install package
or download, unzip, and run the installer directly from the directory:
python setup.py install
If you have Python 2 and Python 3 installed, use pip3 (though not with Anaconda) or make sure the right version is first in your PATH.
Key standard libraries to study:
builtins/pathlib/os
builtins - built in functions.
pathlib - for navigating the file system.
os - for interacting with the operating system and file system.
glob - for searching the file system.
regex - for text and name searching and processing based on patterns.
math - for all things mathsey.
decimal - for floating point operations that help when precision is an issue.
fractions - rational numbers; deal with numbers as genuine fractions.
datetime - for dates and times, plus getting the current date/time.
collections - for managing different storage and search types.
Counter - collection for counting things.
Key external libraries to study:
matplotlib - graphing and mapping.
numpy - mathematics and statistics, especially multi-dimensional array manipulation for data processing.
pandas - visualisation and data analysis.
tkinter - Graphical User Interfaces (windows etc.)
beautifulsoup - web analysis.