Python Standard Modules :: WTF Quick Card
Python is an extremely extensible language in that you can add new capabilities by importing modules.
Here are just a slim few, but a widely used all throughout the day to day process of programming within python, so here’s for anyone that needs a WTF Quick Card…
sys – Allows interaction with the Python system:
- exit() – exit!
- argv – access command line arguments
- path – access the system module search path
- ps1 – change the ‘>>>’ python prompt!
os – Allows interaction with the operating system:
- name – the current operating system, useful for portable programs
- system – execute a system command
- mkdir – create a directory
- getcwd – find the current working directory
re – Allows manipulation of strings with Unix style regular expressions
- search – find pattern anywhere in string
- match – find at beginning only
- findall – find all occurences in a string
- split – break into fields separated by pattern
- sub,subn – string substitution
math – Allows access to many mathematical functions:
- sin,cos etc – trigonometrical functions
- log,log10 – natural and decimal logarithms
- ceil,floor – ceiling and floor
- pi, e – natural constants
time – time(and date) functions
- time – get the current time (expressed in seconds)
- gmtime – convert time in secs to UTC (GMT)
- localtime – convert to local time instead
- mktime – inverse of localtime
- sleep – pause program for n seconds
random – random number generators – useful for games programming!
- randint – generate random integer between inclusive end points
- sample – generate random sublist from a bigger list
- seed – reset the number generator key
Remember this is just a SLIM bit of what’s instore for you that Python has, there are literally dozens of modules given too you with Python, then plenty more you can download!
Remember that using these within your code, you need to first IMPORT them as such:
>>>import SimpleXMLRPCServer as s
>>>s.SimpleXMLRPCRequestHandler()
Notice the above example is a shorter way of calling this module rather than typeing out the FULL SimpleXMLRPCServer
Just saves us time in typing, unless you have an IDE that does it all for you by autocompletion… I prefer VIM for my IDE… So WTF, get it done and >>>import WTFNix.com