How to be a happy programmer (with Python) ? 2/3
In the series of the Python "features" that makes me happy last time i began with two concepts, the with statement and the list comprehensions, now i'm going to talk about Multiple assignments and the import aliases.
- Multiple assignments
It's a simple idea that lets you return a series of value and on the other end assign those multiple values at the same time, example when you're splitting a string or extracting groups from a regular expression : [sourcecode language="python"] >>> split_me ="here,we, are,again" # splitting we'll get a list of values >>> split_me.split(",") ['here', 'we', ' are', 'again'] # if you don't know the number of values you're going to have # you can't use this features, example : >>> (start,end) = split_me.split(",") Traceback (most recent call last): File "", line 1, in ValueError: too many values to unpack # but if you know that there's going to be n values : >>> (start,end) = split_me.split(" ") >>> start 'here,we,' >>> end 'are,again' [/sourcecode]
- Import aliases
It means what it says, when you import a library or module, you can use aliases, example in Django for shortcuts : [sourcecode language="python"] # this is extracted from my own code : from django.http import HttpResponse, HttpResponseRedirect as redirect from django.shortcuts import render_to_response as render</pre> [/sourcecode]
I won't start to talk about the standard library as a whole, or libs like Numpy, Scypy, scikit-learn, .... that makes it so easy to just think in Python.
And you ? What are the Python constructs (2.x or 3.x) that makes you feel happy and efficient at the end of the day ?
Newsletter
Stay updated with new articles.
Keep reading
How to be a happy programmer (with Python) ? 1/3
I've just watched [Hillary Mason's talk in Pycon 2011](http://pycon.blip.tv/file/4878710/ "Hillary Mason") : http://pycon.blip.tv/file/4878710/ And that got me thinking about all the python constructs...
Mar 18, 2011New Year's Python Meme 2012
### 1. What is the coolest Python application, framework or library you have discovered in 2012? Mainly for [APPARTINFO](http://www.appartinfo.com "APPARTINFO"), but not only, i've been using every s...
Dec 28, 2012
State of the Python/PyPi dependency graph
I usually work in Java/Maven environment, so when I explain to people that Python also has a package manager - a bit less heavy than maven - and that it's working pretty well, I always have to answer...
Jan 5, 2013
No comments yet. Be the first to comment!