<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.darenet.org/skins/common/feed.css?12"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Python en:Standard Library - Revision history</title>
		<link>http://wiki.darenet.org/index.php?title=Python_en:Standard_Library&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.15.1</generator>
		<lastBuildDate>Thu, 21 May 2026 04:56:14 GMT</lastBuildDate>
		<item>
			<title>Admin:&amp;#32;1 revision</title>
			<link>http://wiki.darenet.org/index.php?title=Python_en:Standard_Library&amp;diff=5554&amp;oldid=prev</link>
			<description>&lt;p&gt;1 revision&lt;/p&gt;

		&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
		&lt;col class='diff-marker' /&gt;
		&lt;col class='diff-content' /&gt;
		&lt;col class='diff-marker' /&gt;
		&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 02:52, 3 April 2010&lt;/td&gt;
		&lt;/tr&gt;
		&lt;!-- diff generator: internal 2026-05-21 04:07:36 --&gt;

&lt;!-- diff cache key wiki:diff:version:1.11a:oldid:5553:newid:5554 --&gt;
&lt;/table&gt;</description>
			<pubDate>Sat, 03 Apr 2010 02:52:49 GMT</pubDate>			<dc:creator>Admin</dc:creator>			<comments>http://wiki.darenet.org/Talk:Python_en:Standard_Library</comments>		</item>
		<item>
			<title>96.227.115.124:&amp;#32;/* Introduction */</title>
			<link>http://wiki.darenet.org/index.php?title=Python_en:Standard_Library&amp;diff=5553&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Introduction&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
The Python Standard Library contains a huge number of useful modules and is part of every standard Python installation. It is important to become familiar with the Python Standard Library since many problems can be solved quickly if you are familiar with the range of things that these libraries can do.&lt;br /&gt;
&lt;br /&gt;
We will explore some of the commonly used modules in this library. You can find complete details for all of the modules in the Python Standard Library in the [http://docs.python.org/dev/3.0/library/ 'Library Reference' section] of the documentation that comes with your Python installation.&lt;br /&gt;
&lt;br /&gt;
Let us explore a few useful modules.&lt;br /&gt;
&lt;br /&gt;
; Note&lt;br /&gt;
: If you find the topics in this chapter too advanced, you may skip this chapter. However, I highly recommend coming back to this chapter when you are more comfortable with programming using Python.&lt;br /&gt;
&lt;br /&gt;
== sys module ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module contains system-specific functionality. We have already seen that the &amp;lt;tt&amp;gt;sys.argv&amp;lt;/tt&amp;gt; list contains the command-line arguments.&lt;br /&gt;
&lt;br /&gt;
Suppose we want to check the version of the Python command being used so that, say, we want to ensure that we are using at least version 3. The &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module gives us such functionality.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; import sys&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; sys.version_info&lt;br /&gt;
(3, 0, 0, 'beta', 2)&lt;br /&gt;
&amp;gt;&amp;gt;&amp;gt; sys.version_info[0] &amp;gt;= 3&lt;br /&gt;
True&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;sys&amp;lt;/tt&amp;gt; module has a &amp;lt;tt&amp;gt;version_info&amp;lt;/tt&amp;gt; tuple that gives us the version information. The first entry is the major version. We can check this to, for example, ensure the program runs only under Python 3.0:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: versioncheck.py&lt;br /&gt;
import sys, warnings&lt;br /&gt;
if sys.version_info[0] &amp;lt; 3:&lt;br /&gt;
    warnings.warn(&amp;quot;Need Python 3.0 for this program to run&amp;quot;,&lt;br /&gt;
        RuntimeWarning)&lt;br /&gt;
else:&lt;br /&gt;
    print('Proceed as normal')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $ python2.5 versioncheck.py&lt;br /&gt;
    versioncheck.py:6: RuntimeWarning: Need Python 3.0 for this program to run&lt;br /&gt;
      RuntimeWarning)&lt;br /&gt;
    &lt;br /&gt;
    $ python3 versioncheck.py&lt;br /&gt;
    Proceed as normal&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We use another module from the standard library called &amp;lt;tt&amp;gt;warnings&amp;lt;/tt&amp;gt; that is used to display warnings to the end-user. If the Python version number is not at least 3, we display a corresponding warning.&lt;br /&gt;
&lt;br /&gt;
== logging module ==&lt;br /&gt;
&lt;br /&gt;
What if you wanted to have some debugging messages or important messages to be stored somewhere so that you can check whether your program has been running as you would expect it? How do you &amp;quot;store somewhere&amp;quot; these messages? This can be achieved using the &amp;lt;tt&amp;gt;logging&amp;lt;/tt&amp;gt; module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: use_logging.py&lt;br /&gt;
import os, platform, logging&lt;br /&gt;
&lt;br /&gt;
if platform.platform().startswith('Windows'):&lt;br /&gt;
    logging_file = os.path.join(os.getenv('HOMEDRIVE'), os.getenv('HOMEPATH'), 'test.log')&lt;br /&gt;
else:&lt;br /&gt;
    logging_file = os.path.join(os.getenv('HOME'), 'test.log')&lt;br /&gt;
&lt;br /&gt;
logging.basicConfig(&lt;br /&gt;
    level=logging.DEBUG,&lt;br /&gt;
    format='%(asctime)s : %(levelname)s : %(message)s',&lt;br /&gt;
    filename = logging_file,&lt;br /&gt;
    filemode = 'w',&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
logging.debug(&amp;quot;Start of the program&amp;quot;)&lt;br /&gt;
logging.info(&amp;quot;Doing something&amp;quot;)&lt;br /&gt;
logging.warning(&amp;quot;Dying now&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
    $python use_logging.py&lt;br /&gt;
    Logging to C:\Users\swaroop\test.log&lt;br /&gt;
&lt;br /&gt;
If we check the contents of &amp;lt;tt&amp;gt;test.log&amp;lt;/tt&amp;gt;, it will look something like this:&lt;br /&gt;
&lt;br /&gt;
    2008-09-03 13:18:16,233 : DEBUG : Start of the program&lt;br /&gt;
    2008-09-03 13:18:16,233 : INFO : Doing something&lt;br /&gt;
    2008-09-03 13:18:16,233 : WARNING : Dying now&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We use three modules from the standard library - the &amp;lt;tt&amp;gt;os&amp;lt;/tt&amp;gt; module for interacting with the operating system, the &amp;lt;tt&amp;gt;platform&amp;lt;/tt&amp;gt; module for information about the platform i.e. the operating system and the &amp;lt;tt&amp;gt;logging&amp;lt;/tt&amp;gt; module to ''log'' information.&lt;br /&gt;
&lt;br /&gt;
First, we check which operating system we are using by checking the string returned by &amp;lt;tt&amp;gt;platform.platform()&amp;lt;/tt&amp;gt; (for more information, see &amp;lt;tt&amp;gt;import platform; help(platform)&amp;lt;/tt&amp;gt;). If it is Windows, we figure out the home drive, the home folder and the filename where we want to store the information. Putting these three parts together, we get the full location of the file. For other platforms, we need to know just the home folder of the user and we get the full location of the file.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;tt&amp;gt;os.path.join()&amp;lt;/tt&amp;gt; function to put these three parts of the location together. The reason to use a special function rather than just adding the strings together is because this function will ensure the full location matches the format expected by the operating system.&lt;br /&gt;
&lt;br /&gt;
We configure the &amp;lt;tt&amp;gt;logging&amp;lt;/tt&amp;gt; module to write all the messages in a particular format to the file we have specified.&lt;br /&gt;
&lt;br /&gt;
Finally, we can put messages that are either meant for debugging, information, warning or even critical messages. Once the program has run, we can check this file and we will know what happened in the program, even though no information was displayed to the user running the program.&lt;br /&gt;
&lt;br /&gt;
== urllib and json modules ==&lt;br /&gt;
&lt;br /&gt;
How much fun would it be if we could write our own program that will get search results from the web? Let us explore that now.&lt;br /&gt;
&lt;br /&gt;
This can be achieved using a few modules. First is the &amp;lt;tt&amp;gt;urllib&amp;lt;/tt&amp;gt; module that we can use to fetch any webpage from the internet. We will make use of Yahoo! Search to get the search results and luckily they can give us the results in a format called JSON which is easy for us to parse because of the built-in &amp;lt;tt&amp;gt;json&amp;lt;/tt&amp;gt; module in the standard library.&lt;br /&gt;
&lt;br /&gt;
; TODO&lt;br /&gt;
: This program doesn't work yet which [http://bugs.python.org/issue3763 seems to be a bug in Python 3.0 beta 2].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
# Filename: yahoo_search.py&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
if sys.version_info[0] != 3:&lt;br /&gt;
    sys.exit('This program needs Python 3.0')&lt;br /&gt;
&lt;br /&gt;
import json&lt;br /&gt;
import urllib, urllib.parse, urllib.request, urllib.response&lt;br /&gt;
&lt;br /&gt;
# Get your own APP ID at http://developer.yahoo.com/wsregapp/&lt;br /&gt;
YAHOO_APP_ID = 'jl22psvV34HELWhdfUJbfDQzlJ2B57KFS_qs4I8D0Wz5U5_yCI1Awv8.lBSfPhwr'&lt;br /&gt;
SEARCH_BASE = 'http://search.yahooapis.com/WebSearchService/V1/webSearch'&lt;br /&gt;
&lt;br /&gt;
class YahooSearchError(Exception):&lt;br /&gt;
    pass&lt;br /&gt;
&lt;br /&gt;
# Taken from http://developer.yahoo.com/python/python-json.html&lt;br /&gt;
def search(query, results=20, start=1, **kwargs):&lt;br /&gt;
    kwargs.update({&lt;br /&gt;
        'appid': YAHOO_APP_ID,&lt;br /&gt;
        'query': query,&lt;br /&gt;
        'results': results,&lt;br /&gt;
        'start': start,&lt;br /&gt;
        'output': 'json'&lt;br /&gt;
    })&lt;br /&gt;
    url = SEARCH_BASE + '?' + urllib.parse.urlencode(kwargs)&lt;br /&gt;
    result = json.load(urllib.request.urlopen(url))&lt;br /&gt;
    if 'Error' in result:&lt;br /&gt;
        raise YahooSearchError(result['Error'])&lt;br /&gt;
    return result['ResultSet']&lt;br /&gt;
&lt;br /&gt;
query = input('What do you want to search for? ')&lt;br /&gt;
for result in search(query)['Result']:&lt;br /&gt;
    print(&amp;quot;{0} : {1}&amp;quot;.format(result['Title'], result['Url']))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
&lt;br /&gt;
; TODO&lt;br /&gt;
&lt;br /&gt;
How It Works:&lt;br /&gt;
&lt;br /&gt;
We can get the search results from a particular website by giving the text we are searching for in a particular format. We have to specify many options which we combine using &amp;lt;tt&amp;gt;key1=value1&amp;amp;key2=value2&amp;lt;/tt&amp;gt; format which is handled by the &amp;lt;tt&amp;gt;urllib.parse.urlencode()&amp;lt;/tt&amp;gt; function.&lt;br /&gt;
&lt;br /&gt;
So for example, open [http://search.yahooapis.com/WebSearchService/V1/webSearch?query=byte+of+python&amp;amp;appid=jl22psvV34HELWhdfUJbfDQzlJ2B57KFS_qs4I8D0Wz5U5_yCI1Awv8.lBSfPhwr&amp;amp;results=20&amp;amp;start=1&amp;amp;output=json this link in your web browser] and you will see 20 results, starting from the first result, for the words &amp;quot;byte of python&amp;quot;, and we are asking for the output in JSON format.&lt;br /&gt;
&lt;br /&gt;
We make a connection to this URL using the &amp;lt;tt&amp;gt;urllib.request.urlopen()&amp;lt;/tt&amp;gt; function and pass that file handle to &amp;lt;tt&amp;gt;json.load()&amp;lt;/tt&amp;gt; which will read the content and simultaneously convert it to a Python object. We then loop through these results and display it to the end-user.&lt;br /&gt;
&lt;br /&gt;
== Module of the Week Series ==&lt;br /&gt;
&lt;br /&gt;
There is much more to be explored in the standard library such as [http://docs.python.org/dev/library/pdb.html debugging], [http://docs.python.org/dev/3.0/library/getopt.html handling command line options], [http://www.diveintopython.org/regular_expressions/index.html regular expressions] and so on.&lt;br /&gt;
&lt;br /&gt;
The best way to further explore the standard library is to read Doug Hellmann's excellent [http://www.doughellmann.com/projects/PyMOTW/ Python Module of the Week] series.&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
&lt;br /&gt;
We have explored some of the functionality of many modules in the Python Standard Library. It is highly recommended to browse through the [http://docs.python.org/dev/3.0/library/ Python Standard Library documentation] to get an idea of all the modules that are available.&lt;br /&gt;
&lt;br /&gt;
Next, we will cover various aspects of Python that will make our tour of Python more ''complete''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python_en:Exceptions|Previous]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python_en:More|Next]]&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:A Byte of Python|Standard Library]]&lt;/div&gt;</description>
			<pubDate>Thu, 27 Nov 2008 05:58:17 GMT</pubDate>			<dc:creator>96.227.115.124</dc:creator>			<comments>http://wiki.darenet.org/Talk:Python_en:Standard_Library</comments>		</item>
	</channel>
</rss>