Entries : Category [ Python ]
[OpenBSD]  [BSD]  [FreeBSD]  [Linux]  [Security]  [Python]  [Zope]  [Daily]  [e-shell]  [Hacks]  [PostgreSQL]  [OSX]  [Nintendo DS]  [enlightenment]  [Apache]  [Nintendo Wii]  [Django]  [Music]  [Plone]  [Varnish]  [Lugo]  [Sendmail]  [europython]  [Cherokee]  [self]  [Nature]  [Hiking]  [uwsgi]  [nginx]  [cycling]  [Networking]  [DNS] 

26 octubre

Aprender Python

o como me gustaría fomentar su uso...

Vamos a ver, segundo post en spanish que hago en el nuevo blog. Intentare en la medida de lo posible saltarme caracteres especiales de nuestro idioma, al menos mientras no solucione los problemas de codificaciones que tengo ahora mismo (una mezcla entre utf-8 e iso-8859-15) que hace que esos mismos caracteres no se vean bien.

Dicho esto, abro el debate:

Llevo ya tiempo utilizando Python como mi lenguaje de programacion preferente, lo que me ha permitido alcanzar cierto nivel de conocimiento sobre el mismo, y llevo ya cierto tiempo intentando organizar algo relacionado con Python a nivel local (entendamos por local Lugo -> Galicia -> Spain).

Evidentemente no soy un guru, ni mucho menos, y seguro que rebuscando un poco consigo encontrar a gente que sepa bastante mas que yo del tema en esta zona, pero ahi va mi apuesta:

Hago un llamamiento para saber cuanta gente estaria dispuesta a sacrificar una o dos horas semanales o quincenales, para hacer unos cursos/charlas/eventos relacionados con Python

Mi idea consistiria en comenzar con unas breves nociones del lenguaje, primeros scripts, ir avanzando, y si pudiese ser intercalar esas clases con cosas como introducciones a Zope, Django o Turbogears, desarrollo con PyGTK y PyQT, PyGame y las diferentes posibilidades que un lenguaje tan completo nos ofrece.

La organizacion correria por mi cuenta (al principio) y de Codigo23, evidentemente la asistencia seria abierta/gratuita para todo el que quisiese participar y el unico requisito seria el tener ganas de aprender y de aportar cosas conforme se vaya avanzando en el tema.

¿Que os parece? ¿interesante? ¿aburrido? ¿os animais? ¿si? ¿no?

Por favor, a todos aquellos que puedan estar interesados, que respondan con un comentario dando algun tipo de referencia para que pueda ponerme en contacto con vosotros.

Posted by wu at 23:18 | Comments (0) | Trackbacks (0)
23 noviembre

a, b, c, d, e....

or how to get all the letter from the alphabet...

Hey, that's Python, it is easy!

[albaricoque] ~> python
Python 2.5.1 (r251:54863, Jul 30 2007, 20:56:08)
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> import string
>>> string.lowercase

Just import the string module and call the proper method and et voilá!, you are done.

QUICK UPDATE: from betabug do not import the whole string method, instead, import just the lowercase method:

[albaricoque] ~> python
Python 2.5.1 (r251:54863, Jul 30 2007, 20:56:08)
[GCC 3.4.6 [FreeBSD] 20060305] on freebsd6
Type "help", "copyright", "credits" or "license" for more information.
>>> from string import lowercase
>>> lowercase

Why? read that to learn more about the reasons.

Posted by wu at 16:02 | Comments (0) | Trackbacks (0)
03 enero

bunker time: web frameworks

or how to spend some time with your friends...

Yesterday, a new bunker took place. This time I met r0sk at home, we got some pizza and after some talking we began the bunker itself.

The proposal for this bunker was to create a simple bookmarks manager tool. It had to be a simple webapp that will allow people to manage their bookmarks in an easy way.

After thinking a little bit about the webapp background, r0sk began to create it using a well-known php framework, cakephp . He showed me how to create a cake project, the art of baking and how to generate a CRUD interface in an automatic way. He played a little bit with cake's views and its template system. He downloaded a layout/design from freecsstemplates and he added it to the webapp.

Somehow later, it was my turn, and I began to create the webapp on top of django, a well-known web development framework based on python. I began explaining him some basic differences with php-based frameworks, just to show him how to create a django site and a django app. After that, I followed the usual procedure, editing the settings file, running syncdb, then adding the admin interface and finally creating some models, views and templates and adapting the freecsstemplates design to my app.

Unfortunately, time was over, and r0sk had to leave, so we ended the bunker before finishing the job, but we will get back to it soon.

Conclusion: cakephp is a nice framework, it doesn't seem to be difficult to learn, and it does allow you to automate a lot of work when talking about web development. But... I have to admit that I prefer django. Its pythonic style is worth a test (at least a test)

Posted by wu at 23:00 | Comments (0) | Trackbacks (0)
18 enero

bunker time: web frameworks (II)

or how to finish the job...

Almost one week ago I met r0sk once again at home, just to finish what we began in the first web frameworks bunker some weeks ago.

r0sk have posted already about it, just the day after the bunker itself. It took me a whole week to find some time to write about it, because those last 7 days were a completely madness.

In this second bunker of the year we followed the web framework discussion and demostration from the point where we left it in the first one.

update: I've added some pics, so you can notice the atmosphere inside a bunker ;D

r0sk showed me an advanced version of the cakephp based bookmark manager, explaining the more important things about it, and how some things should be done to get it working properly.

r0sk showing CakePHP power

After that brief explanation, we focused ourselves in the django version of it, because I didn't have the time to add all the functions r0sk added to the cakephp one, and that was perfect for adding them now and show r0sk how it is done in django.

I showed r0sk how to manage web forms using both newforms and modelforms, how to customize them, how to add custom .save() methods and how to play with add/modify views.

Wu and django and django and Wu

After a while, we got to a very nice bookmark manager implementation, which you can see now here:


It is still a -beta version (a lot of work should be done before it reaches production state), but it was worth of it if we have learned some from it.

Posted by wu at 13:36 | Comments (0) | Trackbacks (0)
29 abril

Macports and python 2.5

or how you can get yourself mad if you do not read this one...

Some weeks ago I upgraded my macbook from Tiger to Leopard. Right after the upgrade, I installed the usual tools I need for work, like Python, using MacPorts.

Everything was ok, but one thing keeps annoying me all this time... until some minutes ago.

When using the python console, I got a weird behaviour when trying to get entries from the console buffer, and things like that. Let's see it with an example:

snowball:~ wu$ python
Python 2.5.2 (r252:60911, Apr 29 2008, 23:50:14)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> ^[[A

That's what I got when pressing up to access the import os command I just executed before. Some other things didn't work as expected, like pressing the tab key for indentation... pretty annoying.

It didn't help that it only happened with the 2.5 version of the interpreter, python 2.4 worked fine.

Just a while ago, I find the solution for that little problem, installing the py25-readline package:

snowball:~ wu$ sudo port -v install py25-readline

Seems like the people behind MacPorts separate some python 2.5 components into separate subpackages (that's why python2.4 didn't have such problem).

After installed that package, I can enjoy the interpreter experience as usual:

snowball:~ wu$ python
Python 2.5.2 (r252:60911, Apr 29 2008, 23:50:14)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import os

(the second import os appeared when pressing up to access the buffer contents).

Posted by wu at 23:20 | Comments (0) | Trackbacks (0)
13 junio

Problem with ssl in Python 2.5

macports, macports, macports... WTF

I'm beginning to think about the posibility that installing Python from MacPorts in Leopard, and forgetting about the default version that comes with the operating system is not a good idea.

Seems like the guy behind the python25 port decided to split some of the builtin modules into separate ports (I'm not going to explain my oppinion about splitting things into small packages here :D) and today I found that SSL socket support is one of those separate packages.

I was working on a module to add support for sending data by mail from a webapp I've created on top of Django. I followed all the steps in the official docs, so I added some lines into my project settings.py:

# SMTP Settings
DEFAULT_FROM_EMAIL = 'info@gospamyourself.net'

As I've set EMAIL_USE_TLS to True, the django internals code that will send the email for me will try to use a secure TLS link to send the email to the server.

I saved the settings and tried my code, just to notice an ugly message:

'module' object has no attribute 'ssl'

more precisely:

File "/opt/local/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  82.                 response = callback(request, *callback_args, **callback_kwargs)
File "/opt/local/lib/python2.5/site-packages/django/contrib/auth/decorators.py" in __call__
  67.             return self.view_func(request, *args, **kwargs)
File "/Users/wu/codigo23/devel_python/Beyle/FMJJ/../FMJJ/beyle/views.py" in enviar_por_mail
  2009.         email_obj.send()
File "/opt/local/lib/python2.5/site-packages/django/core/mail.py" in send
  259.         return self.get_connection(fail_silently).send_messages([self])
File "/opt/local/lib/python2.5/site-packages/django/core/mail.py" in send_messages
  162.         new_conn_created = self.open()
File "/opt/local/lib/python2.5/site-packages/django/core/mail.py" in open
  130.                 self.connection.starttls()
File "/opt/local/lib/python2.5/smtplib.py" in starttls
  605.             sslobj = socket.ssl(self.sock, keyfile, certfile)

Exception Type: AttributeError at /beyle/obra/2873/mail/
Exception Value: 'module' object has no attribute 'ssl'

mmm... mumble, mumble (as old mickey mouse should say)

What happened here? it seems like Python wasn't able to connect using the secure link... Let's test if there is any problem with that...

Python comes by default with a set of testing scripts you can use to (know what?) test some functionalities. one of those test scripts is testsocketssl.py, which seemed perfect for do what I needed. But... wait a second... seems like that file doesn't exist in my Python installation:

snowball:~ wu$ ls -l /opt/local/lib/python2.5/test/testsocketssl.py
ls: /opt/local/lib/python2.5/test/testsocketssl.py: No such file or directory
snowball:~ wu$

Only then, I began to think about the posibility of a separated port, so I took a look over the MacPorts database, just to find...

snowball:~ wu$ port search py|grep ssl
py-openssl                     python/py-openssl 0.6          python wrapper around the OpenSSL library
py-pow                         python/py-pow  0.7          Python OpenSSL Wrappers is an interface to the openssl library
py25-socket-ssl                python/py25-socket-ssl 2.5.2        Python secure sockets via OpenSSL
py30-socket-ssl                python/py30-socket-ssl 3.0a3        Python secure sockets via OpenSSL
snowball:~ wu$

There it was! a py25-socket-ssl port. I proceeded installing it:

sudo port -v install py25-socket-ssl

And everything works fine since then. Take care, as some other interesting/important modules (like the new native SQLite support) are in separate ports too. You can get a list of python25 related ports with:

port search py25

And remember, once you find an unusual error, just think about a separate port.

Posted by wu at 17:13 | Comments (0) | Trackbacks (0)
14 agosto

From scripting to object-oriented Python programming

yes, i've borrowed the original title...

"From scripting to object-oriented Python programming" is another great article from the IBM DeveloperWorks series. It covers the transition from procedural programming in PHP or bash to procedural, object oriented and functional programming in Python.

It does it through a simple disk-monitoring example and I think is quite a good read. For you who are on vacation, like r0sk or MarcosBL, there is no excuse and it could be the perfect point to begin reading and learning about such a great programming language.

Ah!, in my oppinion, the best approach is the object-oriented one (talking about the example in that article of course).

Posted by wu at 12:27 | Comments (0) | Trackbacks (0)
25 agosto

How to get a list of months using python

.. dirty dirty dirty... ;D

This is a quick-and-dirty hack that came to my mind this morning. I needed a list where each element is a tuple containing (month number, month name). This little snippet will do the trick:

months_choices = []
for i in range(1,13):
    months_choices.append((i, datetime.date(2008, i, 1).strftime('%B')))

The result will be something like:

>>> months_choices = []
>>> for i in range(1,13):
...     months_choices.append((i, datetime.date(2008, i, 1).strftime('%B')))
>>> months_choices
[(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')]

The name of the month will be translated to you locale configuration (according to python documentation, you can take a look there to replace that with, for example, the abbreviated name). This is a perfect list to be used as the default list of options with a django ChoiceField or MultipleChoiceField form field ;D.

Posted by wu at 11:18 | Comments (4) | Trackbacks (0)
02 junio

I'll be at the europython 2009

yes!, and my first time in .co.uk!

europython.eu, a great place to get in touch with the community

I got the flight tickets, the accomodation and the europython ticket last friday. I'm a little but excited about atteding such a great event.

After being one of the lucky ones that were able to attend the first djangocon last year in Mountain View, I was excited about the idea of the first euro-djangocon. Sadly I could not get to prague for the congress, because of some personal issues.

Not attending the djangocon left some space to think about other options, like the europython conference. This one will take place in Birmingham (uk), from 28th June to 4th July.

First two days (Sunday, Monday) are tutorial days (the perfect place to learn more about python development and some more specific topics). From Tuesday to Thursday there will be three days of interesting talks, covering almost every interesting topic related to the python community, from web to gui development, apis, big projects made on top of python, etc. Finally, the last two days (Friday, Saturday), will be sprint days, that is, the time to help with some python-powered projects (django, turbogears, moinmoin, bazaar, etc).

Sadly, I'll be there only from Monday to Friday, attending mostly to the talks. It would be nice to have some more time and stay there for the sprints, but hey, perhaps next year?

Posted by wu at 14:12 | Comments (0) | Trackbacks (0)
29 junio

heading for Birmingham

europython week: day 1

europython.eu, a great place to get in touch with the community

In a few hours I'll be taking the flight to London (Heathrow). It is a 2-hour flight from A Coruña.

Once we reach Heathrow, we will pick up a rental car (we already have a reservation) and will drive another 2 hours to get to Birmingham.

This will be my first time in England, so I expect the 2-hours drive through the midlands to be a very nice experience (if we manage to drive the other way around, remember that, in england, people drive on the left side of the road!).

We will reach Birmingham at 19:30-20:00 (GMT) probably, time to check in at the hotel and prepare ourselves for tomorrow's day one at the europython conference.

Posted by wu at 07:47 | Comments (0) | Trackbacks (0)
[1]   2   3   Next