Today, I wanted to improve our blog-title-to-permalink function, so that (French) accentuated characters are not simply stripped but rather converted to their non accentuated version. For example, "é" would be converted to "e".
After some googling and (slightly) tweaking what I found, here is the function I use:
noaccents_table = ''.join(map(chr, range(192))) + \
"AAAAAAACEEEEIIIIDNOOOOOxOUUUUYTsaaaaaaaceeeeiiiidnooooo/ouuuuyty"
def latin1_to_ascii(u_str):
return u_str.encode('latin1', 'replace').translate(noaccents_table)
As you can see, it takes a unicode string as argument. Here how you use it:
>>> latin1_to_ascii(u'évidemment')
'evidemment'
Note for later: if I ever need to do it in a more generalized way (not only for latin1), the iconv module (http://pypi.python.org/pypi/iconv) might (or might not) be useful.
Creating a collection manager with Elixir in January issue of Python Magazine
Written on 2009-01-27 14:38.After being in the pipeline for a while, my article about Elixir was published in the January issue of Python Magazine. To my surprise, it even made the cover. Maybe, the editors meant it as a little present for my birthday (which is today), who knows... ;-)
Within the article, I build a simple collection manager using Elixir, SQLAlchemy, CherryPy and Genshi. This is the first time I write an article for a technical magazine, and I would really love to hear what people think about it.
Update: As I have been given access to the PDF version of the issue, I noticed the "Useful/Related Links" of my article are not the ones I put there (and are completely unrelated -- I wonder where they come from?). For what it's worth here are the links that should have been included:
- Source code for the program built within the article - http://www.openhex.com/products/elixir/pymag
- Data Mapper Pattern - http://www.martinfowler.com/eaaCatalog/dataMapper.html
- Active Record Pattern - http://www.martinfowler.com/eaaCatalog/activeRecord.html
- REST - http://en.wikipedia.org/wiki/Representational_State_Transfer
Now I understand why there was not any hit on the page holding the application source code...
Update: The version they distribute now has been corrected.
If programming languages were religions...
- Lisp would be Zen Buddhism - There is no syntax, there is no centralization of dogma, there are no deities to worship. The entire universe is there at your reach - if only you are enlightened enough to grasp it. Some say that it's not a language at all; others say that it's the only language that makes sense.
- Perl would be Voodoo - An incomprehensible series of arcane incantations that involve the blood of goats and permanently corrupt your soul. Often used when your boss requires you to do an urgent task at 21:00 on friday night.
- Python would be Humanism - It's simple, unrestrictive, and all you need to follow it is common sense.
For the full list, see: http://www.aegisub.net/2008/12/if-programming-languages-were-religions.html
- 1
