<?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>Núvols Gratis! &#187; Python</title>
	<atom:link href="http://nuvolsgratis.cat/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://nuvolsgratis.cat</link>
	<description>Cumulunimbus, cirrus i altres parides estratosfèriques</description>
	<lastBuildDate>Mon, 20 Dec 2010 17:56:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Spotify + Ubuntu + Wine + notify-osd = Spotify-notify</title>
		<link>http://nuvolsgratis.cat/spotify-ubuntu-wine-notify-osd-spotify-notify/</link>
		<comments>http://nuvolsgratis.cat/spotify-ubuntu-wine-notify-osd-spotify-notify/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 22:11:56 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[Música]]></category>
		<category><![CDATA[Programació]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Spotify]]></category>
		<category><![CDATA[Wine]]></category>

		<guid isPermaLink="false">http://nuvolsgratis.cat/?p=302</guid>
		<description><![CDATA[Sota aquest títol tan matemàtic s&#8217;amaga una petita joia de la corona. M&#8217;explico: porto un temps buscant alguna manera d&#8217;obtenir el títol de la cançó que escolto des d&#8217;Spotify a Ubuntu (a través de Wine). Avui, gairebé per casualitat, he trobat el programa adequat: spotify-notify. El programa, escrit amb el meu estimadíssim python, fa servir [...]]]></description>
			<content:encoded><![CDATA[<p>Sota aquest títol tan matemàtic s&#8217;amaga una petita joia de la corona. M&#8217;explico: porto un temps buscant alguna manera d&#8217;obtenir el títol de la cançó que escolto des d&#8217;Spotify a Ubuntu (a través de Wine). Avui, gairebé per casualitat, he trobat el programa adequat: <strong><a href="http://code.google.com/p/spotify-notify/">spotify-notify</a></strong>.</p>
<p>El programa, escrit amb el meu estimadíssim python, fa servir el notificador <em>notify-osd</em> per avisar-nos de quan Spotify canvia de cançó. És molt fàcil d&#8217;executar: de fet, només cal descarregar un arxiu, instal·lar unes llibreries i executar el programa:</p>
<p><code>python spotify-notify.py</code></p>
<p>Llavors buscarà a Last.fm el nom de l&#8217;artista i el títol de la cançó i n&#8217;obtindrà la portada del disc del primer resultat. Pot ser que no trobi cap portada, i llavors dóna un error, però l&#8217;avís es mostra igualment. Teniu captures de pantalla a la pàgina del projecte.</p>
<p>L&#8217;únic problema és que fa mig any que no s&#8217;actualitza i em dóna certs problemes, com dic, si no troba la portada de l&#8217;àlbum, però sempre es pot modificar el programa. Unes quantes idees:</p>
<ul>
<li>Si no troba la portada a Last.fm, fer servir l&#8217;API d&#8217;Spotify per aconseguir la URL d&#8217;Spotify de la cançó i agafar la portada de la pàgina de la cançó (per exemple, d&#8217;<a href="http://open.spotify.com/track/4YuGSDJIJYZuWKCQqh96Mo">aquí</a>)</li>
<li>Aconseguir que el programa funcioni des que s&#8217;engegui l&#8217;ordinador o, almenys, des que s&#8217;engegui l&#8217;Spotify</li>
<li>Fer una llista de les cançons més escoltades, o les recentment escoltades&#8230;</li>
<li>La teva idea aquí</li>
</ul>
<p>Com sempre, això del brainstorming pot arribar a ser molt llarg&#8230; Algú s&#8217;hi anima a provar-ho? Segur que no és gaire difícil <img src='http://nuvolsgratis.cat/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Spotify + Ubuntu + Wine + notify osd = Spotify notify" class='wp-smiley' title="Spotify + Ubuntu + Wine + notify osd = Spotify notify" /> </p>
]]></content:encoded>
			<wfw:commentRss>http://nuvolsgratis.cat/spotify-ubuntu-wine-notify-osd-spotify-notify/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: Ous de Pasqua</title>
		<link>http://nuvolsgratis.cat/python-ous-de-pasqua/</link>
		<comments>http://nuvolsgratis.cat/python-ous-de-pasqua/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 11:30:04 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[Programació]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://nuvolsgratis.cat/?p=244</guid>
		<description><![CDATA[Efectivament, Python fa homenatge als Monty Python (que és d&#8217;on va sortir el nom) i té alguns ous de pasqua ben divertits o curiosos: Per exemple, si estem a Python 3.0 podem cridar al mòdul antigravity: &#62;&#62;&#62; import antigravity I se&#8217;ns obrirà una finestra a una tira còmica de XKCD (que, per cert, recomano moltíssim). [...]]]></description>
			<content:encoded><![CDATA[<p>Efectivament, Python fa homenatge als Monty Python (que és d&#8217;on va sortir el nom) i té alguns ous de pasqua ben divertits o curiosos:</p>
<p>Per exemple, si estem a Python 3.0 podem <a href="http://svn.python.org/view/python/trunk/Lib/antigravity.py?view=markup&#038;pathrev=66902">cridar al mòdul <code>antigravity</code></a>:</p>
<pre class="brush: python; title: ;"> &gt;&gt;&gt; import antigravity </pre>
<p>I se&#8217;ns obrirà una finestra a <a href="http://xkcd.com/353/">una tira còmica de XKCD</a> (que, per cert, recomano moltíssim). Si no estem a Python 3.0, podem fer això:</p>
<pre class="brush: python; title: ;">&gt;&gt;&gt;import webbrowser
&gt;&gt;&gt;webbrowser.open(&quot;http://xkcd.com/353/&quot;)
</pre>
<p>I farà el mateix efecte.</p>
<p><span id="more-244"></span>Un altre seria fer:</p>
<pre class="brush: python; title: ;">
&gt;&gt;&gt; import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!</pre>
<p>Això ens dóna el codi Zen de Python <img src='http://nuvolsgratis.cat/wp-includes/images/smilies/icon_smile.gif' alt="icon smile Python: Ous de Pasqua" class='wp-smiley' title="Python: Ous de Pasqua" />  A més, si ara fem <code>print this.s</code>ens donarà el mateix codi Zen però amb les lletres de les paraules substituides per altres.</p>
<p>Un altre seria:</p>
<pre class="brush: python; title: ;">&gt;&gt;&gt; import __hello__
Hello world...
</pre>
<p>I l&#8217;últim de tots és:</p>
<pre class="brush: python; title: ;">&gt;&gt;&gt; from __future__ import braces
SyntaxError: not a chance (&lt;pyshell#4&gt;, line 1)</pre>
]]></content:encoded>
			<wfw:commentRss>http://nuvolsgratis.cat/python-ous-de-pasqua/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: crear una llista de llistes buides</title>
		<link>http://nuvolsgratis.cat/python-crear-una-llista-de-llistes-buides/</link>
		<comments>http://nuvolsgratis.cat/python-crear-una-llista-de-llistes-buides/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 23:16:04 +0000</pubDate>
		<dc:creator>Marc</dc:creator>
				<category><![CDATA[Programació]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://nuvolsgratis.cat/?p=236</guid>
		<description><![CDATA[Segons la documentació oficial de Python, si fem: &#62;&#62;&#62; lists = [[]] * 3 &#62;&#62;&#62; lists [[], [], []] &#62;&#62;&#62; lists[0].append(3) &#62;&#62;&#62; lists [[3], [3], [3]] Ens donarà problemes, perquè a la primera fila el que fem és crear tres punters al mateix lloc. És a dir, que tenim una llista d&#8217;un sol element i [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange">Segons la documentació oficial de Python</a>, si fem:</p>
<pre class="brush: python; title: ;">
&gt;&gt;&gt; lists = [[]] * 3
&gt;&gt;&gt; lists
[[], [], []]
&gt;&gt;&gt; lists[0].append(3)
&gt;&gt;&gt; lists
[[3], [3], [3]]
</pre>
<p>Ens donarà problemes, perquè a la primera fila <strong>el que fem és crear tres punters al mateix lloc</strong>. És a dir, que tenim una llista d&#8217;un sol element i tres punters que porten a aquest element. Per tant, si modifiquem qualsevol dels elements estem mdificant tots els elements alhora.</p>
<p>Per tant, la solució passa per fer el següent:</p>
<pre class="brush: python; title: ;">
&gt;&gt;&gt; lists = [[] for i in range(3)]
&gt;&gt;&gt; lists[0].append(3)
&gt;&gt;&gt; lists[1].append(5)
&gt;&gt;&gt; lists[2].append(7)
&gt;&gt;&gt; lists
[[3], [5], [7]]
</pre>
<p><strong>I així ja tenim una llista de llistes buides</strong> preparades per a ser omplertes de qualsevol cosa. </p>
<p>Un codi equivalent a això seria fer el següent, tot i que sembla ser una mica menys òptim perquè fas dos passos:</p>
<pre class="brush: python; title: ;">
&gt;&gt;&gt; lists = []
&gt;&gt;&gt; for i in range(3):
		lists.append([])
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nuvolsgratis.cat/python-crear-una-llista-de-llistes-buides/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

