Do you sometimes feel like you missed something completely obvious, that you should really know about, that could have helped you many times, but you just had no idea that it exists? Something, that you simply assumed “it’s not here, move along”? I felt this way today. How did it happen? Well…
About two weeks ago I felt a huge need of learning something new – a language, framework… Anything! Just to make my brain work a bit harder. After looking around for a few days (sorry Scala and Erlang, you have to wait a bit longer!) I decided to become more familiar with modern cloud application platforms which are becoming more popular these days (or
Paas model in general). Because I think that real projects are much better that rewriting tutorials and reading docs, I decided to write a small Flask web app and deploy it on Heroku. After a few days of learning Flask, coding and running my app on a built-in Flask server I decided to move to a bit more production-ready stage by running it using Gunicorn. And here the story begins…
Yesterday there was a Python Riddle competition on EuroPython. I did quite well, but I didn’t know how well until I saw the results. Then I realized how stupid thing I did to NOT win MacBook. Here’s the short story.
One thing that most Python users learn at the very beginning are list slices – defining a part of the list using the
samplelist[begin:end] syntax. It’s great thing, but – surprisingly – many people don’t even know, that there’s different syntaxt for this, containing one additional parameter – “step”:
samplelist[begin:end:step]. How does it work?
I’ve just bought a ticket! I’ve been there last year and it was a great experience – I hope this time it will be even better :) See you there!
The reason why I like Python so much is the way I can solve some simple problems – solutions are simple and good looking. One of the examples I use to give when asked “what does it mean that code is good looking” is checking if word is a palindrome.
Few weeks ago I’ve bought a new laptop and I’ve installed a new Xubuntu 11.10 on it. Surprisingly (and sadly), when I tried to connect an external display to it, I found out that it’s impossible to do it in “out of the box” version of Xubuntu. I had only a choice to use my external display instead of the internal one or to do a “mirror” configuration, having the same on both displays… Satisfying? No, thanks. I had to find out how to do it in the way I want it to work.
Just a quick tip if you try to set up Hadoop on your Ubuntu 11.10 and you wonder if Maverick’s version will work – yes, it will. Just follow the installation guide inserting this:
deb http://archive.cloudera.com/debian maverick-cdh3 contrib deb-src http://archive.cloudera.com/debian maverick-cdh3 contrib
/etc/apt/sources.list.d/cloudera.list – that’s it!
OK, not exactely – some people (I was one of them) report a
NullPointer Exception. Something similar to this:
1 2 3 4 5 6 7 8 9
Error: java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap. get(ConcurrentHashMap.java:768) at org.apache.hadoop.mapred.ReduceTask$ ReduceCopier$GetMapEventsThread. getMapCompletionEvents(ReduceTask.java:2683) at org.apache.hadoop.mapred. ReduceTask$ReduceCopier$GetMapEventsThread. run(ReduceTask.java:2605)
check your Hadoop host settings (preferrably use IP instead of hostname) and/or
/etc/hosts, which may contain a strange entry with something like
.(null) – just leave one, proper hostname in that line. For me – it started to work after this fix.
I won’t risk saying that it’ll be OK for production enviroment (production server with Ubuntu? OK…), but for testing – it works perfectly.
Few days ago I was talking with my friend about most useful Python features we use almost every day. It was not about any sophisticated tools or libraries, but about the things we use often and which are “given” by the language and its syntax itself – the ones which we like just because they’re “pythonic”. I’ve picked and some of them, which are easy to describe in short devblog article. Even if most of these things should be known for most of the Python developers, I bet that many of you don’t know about at least one of them or just use to forget about using it ;)
Sometimes things don’t work in the way we want them to. Today I was asked why this piece of code is not working properly (OK, given problem was a bit different and much more “real-life-applicable”, but it’s just an example):
1 2 3 4 5 6 7 8 9
def mypush(val, mylist=): mylist.append(val) print mylist, ': ', id(mylist) lst =  mypush(1, lst) mypush(2, lst) mypush(1) mypush(2)
The output is:
1 2 3 4
 : 139750946213184 [1, 2] : 139750946213184  : 139750946218496 [1, 2] : 139750946218496
What’s wrong with it? NOTHING – that’s the way Python should and will behave in such case.
Do you agree? If yes – stop reading, because you won’t learn anything new. Go to XKCD instead. If no – here’s a brief explaination: