Categories
Life Photos Programming

Converting from Python 2 to 3

"You too can solder!"
“You too can solder!”

And here’s a clip I took a while back too: Crissy Field, SF CA

I found a hierarchical tagging Django app called django-categories that I wanted to use in a project. There were a couple of things that I wanted to fix so I forked it and for one reason or another started to build in Python 3 support.

I’ve heard about Python 3. I’ve even written some small programs in it. But library support wasn’t really there back when I tried it and I slunk back to the comfort of Python 2.7. It turns out that all the dependencies for django-categories work in Python 3 and I found a few tools that make version portable code a snap to write. Maybe 2014 is the year of py3k.

Categories
Programming

python list comprehensions, with surprise!

Wasn’t expecting this behavior, but variables used in list comprehensions and with blocks continue to be in scope…

# variables introduced in list comprehensions continue to exist in scope
[a_var for a_var in range(10)]

print "Hey, what's a_var?", a_var

# similar thing happens when using "with"
with open("some_file.txt") as a_file:
    pass

print "Hey, what's a_file?", a_file
python test.py
Hey, what's a_var? 9
Hey, what's a_file? <closed file 'some_file.txt', mode 'r' at 0xb747cee8>
Categories
Programming

git patch mode

A friend at work sent these videos around. If you use git and have ever made more than one feature change in a file between commits, patch mode can help!

http://www.youtube.com/watch?v=Wl0NfWYrvlY

http://www.youtube.com/watch?v=1tqMjJeyKpw