Useful Python modules: Difference between revisions
Pszlachta1 (talk | contribs) No edit summary |
Bszlachta1 (talk | contribs) |
||
| Line 5: | Line 5: | ||
The time module offers functions for getting the current time and date. | The time module offers functions for getting the current time and date. | ||
syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
import time | import time | ||
s = time.asctime() # as string | s = time.asctime() # as string | ||
Latest revision as of 07:58, 1 July 2026
Getting the current time and date
The time module offers functions for getting the current time and date.
import time
s = time.asctime() # as string
i = time.time() # as float
Accessing web pages
The HTML code of web pages and downloadable files from the web can be accessed in a similar way as reading files:
import urllib
url = 'http://www.google.com'
page = urllib.urlopen(url)
print page.read()
Finding out what is in a module
The contents of any module can be examined with:
<syntaxhighlightlang="python"> print dir( name_of_module ) help( name_of_module ) </syntaxhighlight>
Creating plots
The Matplotlib library contains a wide range of possibilities for creating graphs. See the 'gallery' link on http://matplotlib.sourceforge.net for examples. It needs to be installed separately.
from pylab import *
Database access
Numpy is a library that allows operating on arrays and matrices. It needs to be installed separately. See: http://numpy.scipy.org
import numpy
a = numpy.array( [1,2,3,4,5,6] )
print a+10, a*a
Image manipulation
The Python Imaging Library PIL is a powerful tool for working with images (changing formats, resizing, cutting, drawing). It needs to be installed separately. See http://www.pythonware.com/products/pil .