inicio mail me! sindicaci;ón

Archive for February, 2007

Enter Django Snippets

James Bennet just launched a community driven website to collect useful snippets of Django code all in one place. Very nice!

Thanks James!

djangosnippets.org

Updates from Python SVN

I was wondering what was going on in the Python trunk so I made myself skim through the NEWS to see what’s new. Let’s see:

  • Float arguments to seek() are now deprecated:
  1. >>> open(‘t.txt’, ‘w’)   
  2. <open file ‘t.txt’, mode ‘w’ at 0×575218>
  3. >>> f = _
  4. >>> f.write(’sample\n)
  5. >>> f.seek(0.0)
  6. __main__:1: DeprecationWarning: integer argument expected, got float
  • WindowsError correctly displays the windows error code instead of the POSIX one.

  • The break statement inside a try statement results in a SyntaxError:

  1. >>> try:
  2. …     break
  3. except:
  4. …     pass
  5.   File “<stdin>”, line 2
  6. SyntaxError: ‘break’ outside loop
  • with and as are now reserved keywords

  • You can now use heapq.merge() to merge sorted iterables into a single one without pulling all the memory at once:

  1. >>> from heapq import merge
  2. >>> a = [1, 3, 5, 7, 9, 11, 13, 15]
  3. >>> b = [0, 2, 4, 6, 8, 10, 12, 14]
  4. >>> merged = merge(a, b)
  5. >>> for item in merged: print item,
  6. 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  • itertools.izip_longest() has been added to zip sequences with different lengths:
  1. >>> zip(range(10), range(10))
  2. [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
  3. >>> zip(range(10), range(11))
  4. [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]

Notice the additional elements are simply discarded with zip/izip

  1. >>> from itertools import izip_longest
  2. >>> for couple in izip_longest(range(10), range(20)): print couple,
  3. (0, 0) (1, 1) (2, 2) (3, 3) (4, 4) (5, 5) (6, 6) (7, 7) (8, 8) (9, 9) (None, 10) (None, 11) (None, 12) (None, 13) (None, 14) (None, 15) (None, 16) (None, 17) (None, 18) (None, 19)
  4. >>> for couple in izip_longest(range(10), range(20), fillvalue=0): print couple,
  5. (0, 0) (1, 1) (2, 2) (3, 3) (4, 4) (5, 5) (6, 6) (7, 7) (8, 8) (9, 9) (0, 10) (0, 11) (0, 12) (0, 13) (0, 14) (0, 15) (0, 16) (0, 17) (0, 18) (0, 19)

izip_longest fills in the missing values with None by default but you can provide your own fillvalue

  • zipfile module has been improved and now supports decryption.

  • Support for IronPython and Jython has been added to the platform module.

  • The module sets has been deprecated in favor of set/frozenset builtin types.

  • Support for MSVC 8 was added to bdist_wininst

  • If your platform does have ‘chflags’ and/or ‘lchflags’ syscall you can take advantage of it now.

  • Support for HCI protocol on Bluetooth sockets has been added.

There’s a lot, lot more to list go to the NEWS file on the trunk to stay up to date.

Beauty in code

I was building a list of media resources (eg. photos, videos) when I found myself writing the following code to sort that very list:

  1. getdatetime = itemgetter(‘datetime’)
  2. media.sort(key=getdatetime, reverse=True)

It’s not rocket science or anything new but this time I thought the above code lying beneath the expression “code beautiness” (for the record: itemgetter sits in the operator module and media is a list of dictionaries).

So, what’s your example of code beautiness? What python idioms do you find beautiful and maybe “superior” than equivalent in another language?

My Job Went To India (Book review)

Chad Fowler is one of the driving forces in the Rails (and the renewed Ruby’s) community. If you need him to train your team, to consult or speak at your conference he is the man. He’s passionate and smart and that seems a really good combination to me.

His writing abilities gave birth to one of the coolest non-programming-but-for-developers books I’ve read so far.

My Job Went To India is like a journey through the renaissance of your professional career. Chad Fowler based it upon his experience as the leader of an offshore (in Bangalore) team of an IT big company.

The book is divided in six parts: Choosing your market, Investing in your product, Executing, Marketing…not just for suits, Maintaining your edge, If you can’t beat ‘em. All together will give you a lot of useful hints to move on.

I really enjoyed the comparisons throughout the book between Indian way and ours. Some useful insights (and tips) spring from this book.

If you are serious (like I am) about moving on or taking your career to the next step or simply avoid losing your job this is definitely the book for you.

Go get it!

My Job Went To India (And All I Got Was This Lousy Book)
Author: Chad Fowler
ISBN: 0976694018

Please David, use the full date.

I was reading through the Artima forums while I found myself on David Heinemeier Hansson’s blog and I noticed I couldn’t figure out the exact date of his posts.

He uses a partial date without the year and a 12-hour format for the time without the period.

Dhh no Dates

So David, please, be kind, use whatever format you want but insert a full one because it’s irritating the impossibility to date a post in time.

Thank you.