abidibo.net

Just Open Source

Posted in "python"

Django debug with vim and vdebug

dbgp debug django python vim

I'm currently re-configuring all my vim stuff, operation which I perform every x months/years. I used to debug django application using pdb and its set_trace method, this time I decided to integrate a debugging tool inside vim as I always did for PHP using xdebug.

I decided (after some other attempts), to use vdebug, which (as described in the ...

read the full post


Decorators with Python

decorator patterns python

Decorators in python can be quite easy to use and understand, but flexible decorators using the new syntax introduced by python 2.4 can be a bit more complex.

Here I'll try to explain (especially to myself) the world of decorators in python, starting from simple cases and ending with complex ones. Ideas and notions taken from the Pro Django book by Marty Alchin.

Decorators without extra arguments

Let's create a simple cache decorator you can use to store complex operations:

>>> def cache(func):
...   cache_dict = {}
...   def wrapper(*args, **kwargs):
...     key = '%s-%s' % (repr(args), repr(kwargs))
...     if key not in cache_dict:
...       cache_dict[key] = func(*args, **kwargs)
...       print 'cached'
...     return cache_dict[key]
...   return wrapper

A simple decorator function takes ...

read the full post


Python's excess arguments

programming python

What I've always really appreciated of python is the ability to give a function an arbitrary number of positional and keyword arguments, something that in PHP is not possible and is indeed very powerful.

When declaring a function, we can define 4 different types of arguments:

  • required arguments
  • optional arguments (a default is provided)
  • excess positional arguments
  • excess keyword arguments

for example:

def myfunc(a, b=3, *c, **d)
  • a is a required argument
  • b is an optional one since it's default value it's 3
  • the single asterisk before the c argument allows the function to accept any number of positional arguments
  • the two asterisks before the d argument allow the function to support arbitrary kewyword arguments

The order of ...

read the full post


AWR - abidibo's web radio software

awr gtk python software

Today I'll introduce you AWR, my first python/GTK software which actually acts as an interface to mplayer in order to manage web radio streams.

AWR is a free, open source, python project, the code is hosted on github, feel free to use, fork, contribute and so on...

License

© 2013 Stefano Contini - MIT License (http://opensource.org/licenses/MIT).

Features

  • The web radios appearing in the interface inside genre-tabs are configurable through a simple json file, you can add ...

read the full post


Your Smartwatch Loves Tasker!

Your Smartwatch Loves Tasker!

Now available for purchase!

Featured