Archive for the ‘python’ Category

FLISOL 2008 in São Paulo – Python Talk

Friday, April 25th, 2008

I’ll give a talk about Python in FLISOL 2008 São Paulo. It’s scheduled to start at 15h00. It’s a basic talk for people who code in other languages and don’t know much about Python.

Take a look here for more information about FLISOL.

PyPy 2.5 features: __hash__ behavior

Thursday, April 24th, 2008

One small change in Python 2.5 is the __hash__ method behavior. In earlier versions the __hash__ method was supposed to return a normal integer always, but now due to changes in the id() builtin function the __hash__ method behavior was changed and it can return a long or an int.

This was easy to change in PyPy, the hash() builtin function implementation is part of the ObjectSpace as almost all the builtin functions and types.

It’s in pypy/objspace/descroperation.py:

def hash(space, w_obj):
        w_hash = space.lookup(w_obj, '__hash__')
        if w_hash is None:
            if space.lookup(w_obj, '__eq__') is not None or \
               space.lookup(w_obj, '__cmp__') is not None:
                raise OperationError(space.w_TypeError,
                                     space.wrap("unhashable type"))
            return default_identity_hash(space, w_obj)
        w_result = space.get_and_call_function(w_hash, w_obj)
        if space.is_true(space.isinstance(w_result, space.w_int)):
            return w_result
        else:
            raise OperationError(space.w_TypeError,
                     space.wrap("__hash__() should return an int or long"))

One don’t even need to know PyPy well to understand that the lines

if space.is_true(space.isinstance(w_result, space.w_int)):
    return w_result
else:
    raise OperationError(space.w_TypeError,
             space.wrap("__hash__() should return an int or long"))

are responsible for raising a TypeError when the returning value from __hash__ is not an integer.

So just changing the condition

space.is_true(space.isinstance(w_result, space.w_int)):

to

(space.is_true(space.isinstance(w_result, space.w_int)) or
 space.is_true(space.isinstance(w_result, space.w_long))):

will solve this, I hope!

But that’s not all the code needed, I promised Carl to write tests for everything, but as I like to use TDD (test-driven development) it was already done.

Oh, and should I mention that I love PyPy’s documentation? Thanks guys!

FISL 9.0 – GameJam and OLPyC Genius

Thursday, April 24th, 2008

At FISL 9.0 occurred the second OLPC GameJam Brasil (if you don’t know what is GameJam, take a quick look here). The difference from the GameJam occurred in São Carlos is this time we were inside FISL, an event with more than 7,000 people attending and not in a nice and peaceful laboratory :-)

Together with all this people there were lots of interesting talks going on simultaneously and a lot of nice people to talk to. Because of this “details” we started coding whit only 6 hours left for the deadline :-)

This GameJam with me were Andrews Medina and Luciano Pacheco, I met both from Python Brasil community (on PyConBrasil last year). We decided to develop a “Genius” clone for the XO, using it’s special “game-keys” and the “tablet position”. With only 6 hours to develop a game you can imagine that we were not even thinking about the graphics at all, but, suddenly a nice guy named came and offered himself to make pictures for our game. It happens that the guy was Valéssio Brito and he is an “Inkscape genius” (sorry… :P ), in less than one hour he made some cool graphics. That re-excited us and we went on with our code (less than one hour left for the deadline).

At 20h05, five minutes after the deadline, we finished the game, installed it in XO and send to the organization. It was very nice and as Pacheco said, it was one of the best experiences I could do in FISL for me :D

I must say that Andrews was shaking (like a “vara verde” as Luciano said) at the time we delivered our game… :P

Valéssio, me, Andrews and Luciano
From left to right: Valéssio, me (with the XO), Andrews and Pacheco

Thanks Pacheco, Andrews and Valéssio, it was very nice to participate :-)

Thanks to the LEC/UFRGS people that organized the GameJam and thanks to the PyGame folks becuase they’ve developed this wonderful library :-)

Supporting Python 2.5 features in PyPy – GSoC 2008

Tuesday, April 22nd, 2008

As you probably know my GSoC proposal to work on PyPy interpreter, supporting the Python 2.5 features, has been accepted. This post is a short explanation of my Google Summer of Code project.

PyPy

The PyPy project aims at producing a flexible and fast Python implementation. The guiding idea is to translate a Python-level description of the Python language itself to lower level languages. Rumors have it that the secret goal is being faster-than-C which is nonsense, isn’t it?

PyPy is divided into the python interpreter and the translator framework. The interpreter is written in RPython (a subset of Python) and the main goal is to provide an easy-to-hack (for python programmers ;) ) Python interpreter.

PyPy’s interpreter currently supports only a few features introduced in Python 2.5, like __index__ (for slicing) and some part of the ‘with’ statement. Also, the 2.5 changes to the language and to the standard library have not been ported yet (although some have been, like the ctypes).

Goal

This proposal idea is to bring Python 2.5 features and changes to PyPy interpreter, this includes porting the modules and writing code for the features it self.

Here are some of the features I’ll work on:

  • PEP 308: Conditional Expressions[*]
  • 328: Absolute and Relative Imports
  • PEP 342: New Generator Features
  • PEP 343: The with statement[*]
  • PEP 352: Exceptions as New-Style Classes

[*] part of this features are already supported by PyPy

Benefits

With support to 2.5 features and changes more the PyPy interpreter will be up-to-date so people who wants to use this features can be happy using PyPy. This probably means more people using PyPy (i hope!) :-)

Why this project?

The first reason I’ve chosen the PyPy project is that I really like their ideas and goals. I was looking for collaborating to it in some way for a long time, but it took me some time to read the docs and to really understand the project.

As I like PyPy ideas and I’m starting to plan my graduation project/bachelor’s thesis, my work on PyPy interpreter will be a big part of it. Maybe I can explain my ideas in another post :-)

I would like to thank Google (and the SoC folks), Python Software Foundation, PyPy and specially to Carl Friedrich Bolz* who will be my GSoC mentor and Leonardo Santagada who helped me to understand PyPy and to write my application.

* morepypy is a blog where PyPy developers talk to the community, it’s not Carl’s personal blog.

Thanks to my friends from Python Brasil community too.

Approved in GSoC

Monday, April 21st, 2008

As mentioned before I’ve applied to GSoC to work on PyPy for the Python Software Foundation.

Today I’m very happy to say that my project got approved and I will work on PyPy interpreter the next three months. It means that a lot of PyPy posts are coming, and the first one will be a introduction to the project, what is PyPy, the interpreter and the translation framework :)

Stay tuned if you are interested in PyPy! Congratulations to everybody that have applied to GSoC this year =)

FISL 9.0 – 1. São Paulo -> Porto Alegre -> FISL!

Sunday, April 20th, 2008

There isn’t words to describe how I’m happy after this 3 days in Porto Alegre, attending to FISL. I’ll try to make a report of what happened, but it’s so much things that I’ll post it in parts.

So this is part one, and it starts at the São Paulo international airport (at Guarulhos-SP) on April 17th. Destination: Porto Alegre, Rio Grande do Sul!

Airplane

With me were my two friends Marcelo Honório and David Kwast. Our flight was scheduled to leave at 4h30am. Well, it left exactly 4h25am, after one hour flying they announced that the Porto Alegre airport was closed due to bad weather conditions, and worse, all near airports were closed so went back to São Paulo international airport. We had to wait until 11am, when the Porto Alegre aiport opened again and all flights that were late started to leave.

After that we finally did it and went to PUC (the university where FISL happened) but what happened there is history for the next post, the first day report :-)

FISL 9.0 – here we go again!

Tuesday, April 15th, 2008

I’m attending to FISL 9.0, the Fórum Internacional Software Livre (or Free Software International Forum) that happens every year in Porto Alegre, Rio Grande do Sul – Brazil, organized by the Brazilian Free Software Association (Associação Software Livre – ASL) and Projeto Software Livre – PSL-BR. I think FISL doesn’t need any introduction at all, it’s a well known and recognized event around the world.

This is the second time I’m going, the first was last year and I was very impressed about the organization, people and talks. It’s a very good chance to meet people that I talk only through mailing lists :-)

This FISL (9.0) is very special for the Brazilian Python community, it’s our first FISL as an association (APyB, Associação Python Brasil/Python Brazil Association) and we already have an exclusive track (called APyB, see the FISL program). In the program you can see the APyB track and the “Development: Python” track, both are about Python talks, but the first was given to APyB by FISL organization, the APyB had 10 slots where it could choose the talks and this talks doesn’t need to pass through the FISL evaluation process.

Is there any reason to think that this isn’t the “Python @ FISL” year? :-)

I hope everybody have a nice FISL!

See you at Porto Alegre!

V GruPy meeting – March, 24 – Report

Monday, March 31st, 2008

The GruPy-SP (São Paulo Python User Group) March meeting happened at Google’s office in São Paulo. The meeting was attended by about 60 people and we had 5 talks. This was a very special meeting because we had talks from Guido, Alex Martelli, Collin Winter and Cary Hull (all by video conference).

Talks:

  • Rodolpho Eckhardt – “PyCon 2008 Trip Report” – Rodolpho made a very nice report of his experience going to Chicago to attend PyCon 2008. It certainly made some of us think about going to PyCon 2009.
  • Cary Hull – “Divmod’s Axiom” – Cary Hull talked about the Axiom ORM, it was a fast talk introducing it features and benefits.
  • Alex Martelli – “Callback design patterns” – Very good technical talk. Details about the use and implementation of Callbacks.
  • Guido van Rossum – “Python 3000″ – Probably the talk that everyone was waiting, It was the same talk that Guido made at PyCon 2008, he showed the main changes that will happen in Python 3000 and what to do to be prepared to change your code from Python 2.x to 3000.
  • Collin Winter – “2to3″ – Very good talk from Collin Winter about how the 2to3 conversion tool works, where it does and where it doesn’t work.

The next meeting will be held on May. We will not have a meeting in April because of FISL (Free Software International Forum) that will happen on April 17th, 18th and 19th at Porto Alegre.

Thanks to everyone who attended, specially to Rodolpho who organized the meeting.

Google Summer of Code 2008

Wednesday, March 26th, 2008

Well, it’s time for students to apply for Google Summer of Code.

What is GSoC ?

You can read about GSoC in their website, but I will try to resume here what is GSoC.

Google pays you (a student) US$ 4500,00 for three months of work on a free/open source software.

First the organizations apply for GSoC as a mentoring organization. Each organization accepted by Google receive slots and distribute this slots in project ideas.

Then the student find a mentoring organization, choose a project (or propose a new one) and asks for a mentor (applying). The organization will choose the students and then monitor the student work. Note that a student can apply for 20 projects but if approved in more than one he will need to choose only one to work.

The student will receive from Google US$ 500,00 when the program starts, then US$ 2000,00 after a month of work and US$ 2000,00 when the program finishes. Obviously the mentor will check the student process/work and decide if he should receive the money or not.

When the student finishes the program, he receives a GSoC t-shirt and a Google certificate (nice! :) ).

Benefits

For students (like me):

  • Contribute do free/open source software
  • Learn and gain experience
  • Get paid to code free/open source software
  • A beautiful t-shirt :)
  • think about your new job offers … :P

For organizations (like Python Software Foundation):

  • More people involved in the development process
  • People getting paid to develop needed features

I’m applying for BlueZ, the project idea is simple, build a high-level interface/layer upon python-dbus to provide the services/interfaces offered by BlueZ by D-Bus.

I’ll probably try to apply to OLPC as well.

I’m also applying (maybe too late) for Python Software Foundation to work on PyPy. The project idea is to support CPython 2.5 features and changes missing in PyPy.

For more information in GSoC I recommend watching this screencast by Titus Brown.

That’s all.

IV GruPy-SP meeting in Santos – Feb, 22 and 23 report

Tuesday, March 25th, 2008

The GruPy-SP (São Paulo Python User Group) February meeting was held at SENAI Santos. It was a two-day event, one day for talks and the other for the Python Bug Day.

First day – Feb, 22 – Talks

Luciano Ramalho and Pedro Werneck talked to approximately 140 students, professors and professionals at SENAI Santos.

Luciano talked about Python being used by big companies as a “secret weapon”, he showed some Python code including PyGame and Django examples and interactive sessions using the Python console.

Pedro showed some of the versatility of Python presenting a script that manipulates a device plugged in the computer parallel port, some web apps and a GUI application using Tkinter.

Most of the audience was not familiar to Python and this was their first contact with the language.

Second day – Feb, 23 – Python Bug Day

14 members of the GruPy-SP went to Santos to work on the Python Bug Day.

The sprint started at 10h00 led by Luciano Ramalho and Rodrigo Bernardo Pimentel (RBP). We listed the bugs that we thought we could fix and then started working in pairs. The sprint went until 16h00 and we fixed five bugs.

Thanks to everyone who attended, specially to Sandro Fernandes and Ricardo Guinody who organized this meeting.