tags/python
blog
http://blog.spang.cc/tags/python/
blog
ikiwiki
2014-04-14T16:32:41Z
PyCon 2014 retrospective
http://blog.spang.cc/posts/PyCon_2014_retrospective/
2014-04-14T16:32:41Z
2014-04-14T16:15:09Z
<p>PyCon 2014 happened. (Sprints are still happening.)</p>
<p>This was my 3rd PyCon, but my first year as a serious contributor to the
event, which led to an incredibly different feel. I also came as a
person running a company building a complex system in Python, and I
loved having the overarching mission of what I'm building driving my
approach to what I chose to do. PyCon is one of the few conferences
I go to where the feeling of acceptance and at-homeness mitigates the
introvert overwhelm at nonstop social interaction. It's truly a special
event and community.</p>
<p>Here are some highlights:</p>
<ul>
<li>I gave a <a href="http://pyvideo.org/video/2639/search-101-an-introduction-to-information-retrie">tutorial about
search</a>,
which was recorded in its entirety... if you watch this video, I
highly recommend skipping the hands-on parts where I'm just walking
around helping people out. <img src="http://blog.spang.cc/tags/python/../../smileys/smile.png" alt=":)" /></li>
<li>I gave a talk! It's called <em>Subprocess to FFI</em>, and you can find the
video
<a href="http://pyvideo.org/video/2640/subprocess-to-ffi-memory-performance-and-why-y">here</a>.
Through three full iterations of dry runs with feedback, I had a ton of fun
preparing this talk. I'd like to give more like it in the future as I
continue to level up my speaking skills.</li>
<li><a href="http://allendowney.com/">Allen Downey</a> came to my talk and found me
later to say hi. Omg amazing, made my day.</li>
<li><a href="https://auxvivres.com/en/">Aux Vivres</a> and <a href="http://www.dieuduciel.com/">Dieu du
Ciel</a>, amazing eats and drink with great
new and old friends. Special shout out to old Debian friends Micah
Anderson, Matt Zimmerman, and Antoine Beaupré for a good time at Dieu
du Ciel.</li>
<li>The Geek Feminism open space was a great place to chill out and always
find other women to hang with, much thanks to Liz Henry for organizing
it.</li>
<li>Talking to the community from the <a href="https://www.inboxapp.com/">Inbox</a>
booth on Startup Row in the Expo hall on Friday. Special thanks for
Don Sheu and Yannick Gingras for making this happen, it was awesome!</li>
<li>The PyLadies lunch. Wow, was that amazing. Not only did I get to meet
Julia Evans (who <a href="http://jvns.ca/blog/2014/04/13/pycon/">also liked meeting
me!</a>), but there was an amazing
lineup of amazing women telling everyone about what they're doing.
This and <a href="https://us.pycon.org/2014/schedule/presentation/182/">Noami Ceder's
touching talk</a>
about openly transitioning while being a member of the Python
community really show how the community walks the walk when it comes
to diversity and is always improving.</li>
<li>Catching up with old friends like Biella Coleman, Selena Deckelmann,
Deb Nicholson, Paul Tagliamonte, Jessica McKellar, Adam Fletcher, and
even friends from the bay area who I don't see often. It was hard to
walk places without getting too distracted running into people I knew,
I got really good at waving and continuing on my way. <img src="http://blog.spang.cc/tags/python/../../smileys/smile.png" alt=":)" /></li>
</ul>
<p>I didn't get to go to a lot of talks in person this year since my
personal schedule was so full, but the PyCon video team is amazing as
usual, so I'm looking forward to <a href="http://pyvideo.org/category/50/pycon-us-2014">checking out the
archive</a>. It really is a
gift to get the videos up while energy from the conference is still so
high and people want to check out things they missed and share the talks
they loved.</p>
<p>Thanks to everyone, hugs, peace out, et cetera!</p>
Django form fields with the same name as Python keywords
http://blog.spang.cc/posts/Django_form_fields_with_the_same_name_as_Python_keywords/
Christine Spang
2010-06-04T03:50:45Z
2010-06-04T00:58:11Z
<p>For <a href="http://www.ksplice.com/">work</a> recently I've been doing some
Django-related tasks that involve talking to an external API with
POSTed forms. Django forms objects are declared by creating a class that
inherits from <code>django.forms.Form</code>, with the fields of the
form declared by declaring attributes of that class. Which works well
and is clean and easy to remember—unless the API you're working
with requires a field with the same name as a Python keyword, such as
<code>return</code>. You can't declare a field like this as an
attribute; it will trigger a syntax error.</p>
<p>I spent some time scratching my head over this, and came up with this as
a workaround after source-diving to find out how <code>Form</code>
objects actually work:</p>
<div class="highlight-py"><pre class="hl"><span class="hl kwa">from</span> django <span class="hl kwa">import</span> forms
<span class="hl kwa">class</span> <span class="hl kwd">ExampleForm</span><span class="hl opt">(</span>forms<span class="hl opt">.</span>Form<span class="hl opt">):</span>
<span class="hl kwa">def</span> <span class="hl kwd">__init__</span><span class="hl opt">(</span>self<span class="hl opt">,</span> data<span class="hl opt">=</span><span class="hl kwa">None</span><span class="hl opt">,</span> files<span class="hl opt">=</span><span class="hl kwa">None</span><span class="hl opt">,</span> auto_id<span class="hl opt">=</span><span class="hl str">'id_%s'</span><span class="hl opt">,</span> prefix<span class="hl opt">=</span><span class="hl kwa">None</span><span class="hl opt">,</span>
initial<span class="hl opt">=</span><span class="hl kwa">None</span><span class="hl opt">,</span> errorclass<span class="hl opt">=</span>ErrorList<span class="hl opt">,</span> label_suffix<span class="hl opt">=</span><span class="hl str">':'</span><span class="hl opt">,</span> empty_permitted<span class="hl opt">=</span><span class="hl kwa">False</span><span class="hl opt">,</span> return_url<span class="hl opt">=</span><span class="hl kwa">None</span><span class="hl opt">):</span>
forms<span class="hl opt">.</span>Form<span class="hl opt">.</span><span class="hl kwd">__init__</span><span class="hl opt">(</span>self<span class="hl opt">,</span> data<span class="hl opt">,</span> files<span class="hl opt">,</span> auto_id<span class="hl opt">,</span> prefix<span class="hl opt">,</span> initial<span class="hl opt">,</span>
errorclass<span class="hl opt">,</span> label_suffix<span class="hl opt">,</span> empty_permitted<span class="hl opt">)</span>
<span class="hl kwa">if</span> return_url <span class="hl kwa">is not None</span><span class="hl opt">:</span>
self<span class="hl opt">.</span>fields<span class="hl opt">[</span><span class="hl str">'return'</span><span class="hl opt">] =</span> forms<span class="hl opt">.</span><span class="hl kwd">CharField</span><span class="hl opt">(</span>widget<span class="hl opt">=</span>forms<span class="hl opt">.</span>HiddenInput<span class="hl opt">,</span> initial<span class="hl opt">=</span>return_url<span class="hl opt">)</span>
</pre></div>
<p>It turns out that the attribute declaration is just syntactic sugar for
creating a dictionary of key/value pairs, which is then stored in the
<code>fields</code> attribute. So we can monkeypatch in extra values after
the translation. Which is somewhat more awkward and ugly, but works in a pinch.</p>
<p>Note that I haven't extensively tested what interactions this may cause with
other forms code, so use with some caution.</p>
principle of most surprise
http://blog.spang.cc/posts/principle_of_most_surprise/
2009-09-25T01:44:54Z
2009-09-25T01:44:54Z
<p>A python example in ipython:</p>
<pre><code>In [1]: for i in range(10):
...: print "i in loop:", i
...:
...:
i in loop: 0
i in loop: 1
i in loop: 2
i in loop: 3
i in loop: 4
i in loop: 5
i in loop: 6
i in loop: 7
i in loop: 8
i in loop: 9
In [2]: print "i out of loop:", i
i out of loop: 9
</code></pre>
<p>This bit me last night while writing some code for a digital communications lab
assignment. I typed the wrong variable name, which was from an inner loop when
I meant to use the element from the outer loop. Is there actually a sane reason
for a loop variable <em>not</em> to go out of scope when the loop ends? Tell me
there's a good reason for it. It took <em>me</em> completely by surprise.</p>