<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mithro rants about stuff &#187; Python</title>
	<atom:link href="http://blog.mithis.net/archives/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.mithis.net</link>
	<description></description>
	<lastBuildDate>Fri, 16 Dec 2011 06:02:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Reading cookies from most Firefox versions&#8230;</title>
		<link>http://blog.mithis.net/archives/python/94-reading-cookies-firefox</link>
		<comments>http://blog.mithis.net/archives/python/94-reading-cookies-firefox#comments</comments>
		<pubDate>Mon, 19 Jan 2009 23:59:49 +0000</pubDate>
		<dc:creator>mithro</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[cookies]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://blog.mithis.net/?p=94</guid>
		<description><![CDATA[Yesterday, I wrote about how to reading the cookies from Firefox 3.0 from Python. This code snippet extends the previous example by adding code which finds the cookie file on various different operating systems (Windows, Linux and Mac OS X). Hope this helps people who need to do this. #! /usr/bin/env python # Reading the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I wrote about how to reading the <a href="http://blog.mithis.net/archives/python/90-firefox3-cookies-in-python">cookies from Firefox 3.0</a> from Python. This code snippet extends the previous example by adding code which finds the cookie file on various different operating systems (Windows, Linux and Mac OS X). Hope this helps people who need to do this.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#! /usr/bin/env python</span>
<span style="color: #808080; font-style: italic;"># Reading the cookie's from Firefox/Mozilla. Supports Firefox 3.0 and Firefox 2.x</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Author: Noah Fontes &lt;nfontes AT cynigram DOT com&gt;, </span>
<span style="color: #808080; font-style: italic;">#         Tim Ansell &lt;mithro AT mithis DOT com&gt;</span>
<span style="color: #808080; font-style: italic;"># License: MIT</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> sqlite2cookie<span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">cStringIO</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">StringIO</span>
    <span style="color: #ff7700;font-weight:bold;">from</span> pysqlite2 <span style="color: #ff7700;font-weight:bold;">import</span> dbapi2 <span style="color: #ff7700;font-weight:bold;">as</span> sqlite
&nbsp;
    con = sqlite.<span style="color: black;">connect</span><span style="color: black;">&#40;</span>filename<span style="color: black;">&#41;</span>
&nbsp;
    cur = con.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    cur.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;select host, path, isSecure, expiry, name, value from moz_cookies&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    ftstr = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FALSE&quot;</span>,<span style="color: #483d8b;">&quot;TRUE&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
    s = <span style="color: #dc143c;">StringIO</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    s.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;&quot;<span style="color: #000099; font-weight: bold;">\</span>
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file!  Do not edit.
&quot;&quot;&quot;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> cur.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        s.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\t</span>%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>
            item<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, ftstr<span style="color: black;">&#91;</span>item<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">startswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.'</span><span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>,
            ftstr<span style="color: black;">&#91;</span>item<span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>, item<span style="color: black;">&#91;</span><span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    s.<span style="color: black;">seek</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
&nbsp;
    cookie_jar = <span style="color: #dc143c;">cookielib</span>.<span style="color: black;">MozillaCookieJar</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    cookie_jar._really_load<span style="color: black;">&#40;</span>s, <span style="color: #483d8b;">''</span>, <span style="color: #008000;">True</span>, <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> cookie_jar
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">cookielib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">logging</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">ConfigParser</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Set up cookie jar paths</span>
<span style="color: #ff7700;font-weight:bold;">def</span> _get_firefox_cookie_jar <span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>:
    profiles_ini = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>path, <span style="color: #483d8b;">'profiles.ini'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">or</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>profiles_ini<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Open profiles.ini and read the path for the first profile</span>
    profiles_ini_reader = <span style="color: #dc143c;">ConfigParser</span>.<span style="color: #dc143c;">ConfigParser</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">;</span>
    profiles_ini_reader.<span style="color: black;">readfp</span><span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span>profiles_ini<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    profile_name = profiles_ini_reader.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Profile0'</span>, <span style="color: #483d8b;">'Path'</span>, <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
    profile_path = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>path, profile_name<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>profile_path<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>profile_path, <span style="color: #483d8b;">'cookies.sqlite'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>profile_path, <span style="color: #483d8b;">'cookies.sqlite'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>profile_path, <span style="color: #483d8b;">'cookies.txt'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>profile_path, <span style="color: #483d8b;">'cookies.txt'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _get_firefox_nt_cookie_jar <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473846</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">_winreg</span>
        <span style="color: #ff7700;font-weight:bold;">import</span> win32api
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">ImportError</span>:
        <span style="color: #dc143c;">logging</span>.<span style="color: black;">error</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Cannot load winreg -- running windows and win32api loaded?'</span><span style="color: black;">&#41;</span>
    key = <span style="color: #dc143c;">_winreg</span>.<span style="color: black;">OpenKey</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">_winreg</span>.<span style="color: black;">HKEY_CURRENT_USER</span>, r<span style="color: #483d8b;">'Software<span style="color: #000099; font-weight: bold;">\M</span>icrosoft<span style="color: #000099; font-weight: bold;">\W</span>indows<span style="color: #000099; font-weight: bold;">\C</span>urrentVersion<span style="color: #000099; font-weight: bold;">\E</span>xplorer<span style="color: #000099; font-weight: bold;">\S</span>hell Folders'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        result = <span style="color: #dc143c;">_winreg</span>.<span style="color: black;">QueryValueEx</span><span style="color: black;">&#40;</span>key, <span style="color: #483d8b;">'AppData'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">WindowsError</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        key.<span style="color: black;">Close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> ret<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> == <span style="color: #dc143c;">_winreg</span>.<span style="color: black;">REG_EXPAND_SZ</span>:
            result = win32api.<span style="color: black;">ExpandEnvironmentStrings</span><span style="color: black;">&#40;</span>ret<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            result = ret<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> _get_firefox_cookie_jar<span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>result, r<span style="color: #483d8b;">'Mozilla<span style="color: #000099; font-weight: bold;">\F</span>irefox<span style="color: #000099; font-weight: bold;">\P</span>rofiles'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _get_firefox_posix_cookie_jar <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">return</span> _get_firefox_cookie_jar<span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'~/.mozilla/firefox'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> _get_firefox_mac_cookie_jar <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># First of all...</span>
    result = _get_firefox_cookie_jar<span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'~/Library/Mozilla/Firefox/Profiles'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> result == <span style="color: #008000;">None</span>:
        result = _get_firefox_cookie_jar<span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'~/Library/Application Support/Firefox/Profiles'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> result
&nbsp;
FIREFOX_COOKIE_JARS = <span style="color: black;">&#123;</span>
    <span style="color: #483d8b;">'nt'</span>: _get_firefox_nt_cookie_jar,
    <span style="color: #483d8b;">'posix'</span>: _get_firefox_posix_cookie_jar,
    <span style="color: #483d8b;">'mac'</span>: _get_firefox_mac_cookie_jar
<span style="color: black;">&#125;</span>
&nbsp;
cookie_jar = <span style="color: #008000;">None</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
    cookie_jar = FIREFOX_COOKIE_JARS<span style="color: black;">&#91;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">name</span><span style="color: black;">&#93;</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">KeyError</span>:
    cookie_jar = <span style="color: #008000;">None</span>
&nbsp;
path = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Path to cookie jar file [%s]: '</span> <span style="color: #66cc66;">%</span> cookie_jar<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> path.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># Some input specified, set it</span>
    cookie_jar = <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">realpath</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">expanduser</span><span style="color: black;">&#40;</span>path.<span style="color: black;">strip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> cookie_jar.<span style="color: black;">endswith</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'.sqlite'</span><span style="color: black;">&#41;</span>:
    cookie_jar = sqlite2cookie<span style="color: black;">&#40;</span>cookie_jar<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
    cookie_jar = <span style="color: #dc143c;">cookielib</span>.<span style="color: black;">MozillaCookieJar</span><span style="color: black;">&#40;</span>cookie_jar<span style="color: black;">&#41;</span></pre></div></div>

</blockquote>
<p><i>Edit: The latest version of this code can be found at <a href="http://blog.mithis.com/cgi-bin/gitweb.cgi">http://blog.mithis.com/cgi-bin/gitweb.cgi</a> and includes numerous fixes and updates.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mithis.net/archives/python/94-reading-cookies-firefox/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>$#%#! UTF-8 in Python</title>
		<link>http://blog.mithis.net/archives/python/91-utf-8-in-python</link>
		<comments>http://blog.mithis.net/archives/python/91-utf-8-in-python#comments</comments>
		<pubDate>Mon, 19 Jan 2009 03:54:08 +0000</pubDate>
		<dc:creator>mithro</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[$LANG]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[sys.stdout]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[utf8]]></category>

		<guid isPermaLink="false">http://blog.mithis.net/?p=91</guid>
		<description><![CDATA[This is not a post about using UTF-8 properly in Python, but doing evil, evil things. Python dutifully respects the $LANG environment variable on the terminal. It turns out that a lot of the time this variable is totally wrong, it&#8217;s set to something like C even though the terminal is UTF-8 encoding. The problem [...]]]></description>
			<content:encoded><![CDATA[<p>This is <b>not</b> a post about using UTF-8 properly in Python, but doing <i>evil, evil</i> things.</p>
<p>Python dutifully respects the $LANG environment variable on the terminal. It turns out that a lot of the time this variable is totally wrong, it&#8217;s set to something like C even though the terminal is UTF-8 encoding. </p>
<p>The problem is that there is no easy way to change a file&#8217;s encoding after it&#8217;s open, well until this horrible hack! The following code will force the output encoding of stdout to UTF-8 even if started with LANG=C.</p>
<blockquote>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># License: MIT</span>
<span style="color: #ff7700;font-weight:bold;">try</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> u<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\u</span>263A&quot;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">Exception</span>, e:
    <span style="color: #ff7700;font-weight:bold;">print</span> e
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">encoding</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> ctypes <span style="color: #ff7700;font-weight:bold;">import</span> pythonapi, py_object, c_char_p
PyFile_SetEncoding = pythonapi.<span style="color: black;">PyFile_SetEncoding</span>
PyFile_SetEncoding.<span style="color: black;">argtypes</span> = <span style="color: black;">&#40;</span>py_object, c_char_p<span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> PyFile_SetEncoding<span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>, <span style="color: #483d8b;">&quot;UTF-8&quot;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">ValueError</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">try</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> u<span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\u</span>263A&quot;</span>
<span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">Exception</span>, e:
    <span style="color: #ff7700;font-weight:bold;">print</span> e</pre></div></div>

</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.mithis.net/archives/python/91-utf-8-in-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

