__FUNCTION__ and __LINE__ in Python

When you want to log something, C pre-processor macros __FUNCTION__ and __LINE__ are quite helpful (althogh the first is a GNU extension for GCC, AFAIK). Python have the __name__ pseudo-variable with the current namespace, but isn’t quite helpful when you want to find where things are going. Fortunately, you can “emulate” __FUNCTION__ and __LINE__ in Python, using the inspect module.

def __line__ ():
    caller = inspect.stack()[1]
    return int (caller[2])

def __function__ ():
    caller = inspect.stack()[1]
    return caller[3]

Yes, both are now functions and not pseudo-variables. But it works.

[pt_BR] Como matar o português

Hoje, vindo para o trabalho, resolvi ler um dos tantos cartazes colados pela cidade sobre a “micro-camêra do 007”. O mais engraçado é que ninguém deve ter percebido que eles tem “o tamanho de um esqueiro” (sic).

Geek += 1

I just increased my geekness a few weeks ago when I completed “Neuromancer“, Willian Gibson most famous work.

Now, I couldn’t read it without seeing the main character (Chase) as the main character of “Hackers”. Actually, Neuromancer really looks like a clash between “Hackers” and “Bladerunner”. Add a little bit of “Matrix” and “I want to be John Malcowich” and there you have it.

There are some pieces around the end, when you have people in zero-g in an acid trip that you can’t really understand what is going on. Other than that, the story moves nicely. But I wouldn’t recomend it, as the confusing parts took a great deal of the climax of the book.

Well, let’s see what I will find next to improve my geekness…

[And “Geek += 1” ’cause that’s one of the books listed on Top 20 Geek Novels]