Generate a random string in hexadecimal is one of those things that you always have to do, from time to time.
As far as I know, the easiest way to do this in python is to import uuid module and run the following code:
uuid.uuid4().hex
With the call above we have 32 hexadecimal characters string (16 random bytes).
Do [...]
Category > Python
Manso Trick: Easy way to generate random hex string in Python
MansoTrick: Convert 24h time string to 12h AM/PM format (Python)
Manso trick to convert from 24h time format to 12h (AM/PM) time format in Python
def ampmformat (hhmmss):
“”"
This method converts time in 24h format to 12h format
Example: “00:32″ is “12:32 AM”
[...]
Unicode support in Python: Frustrations and Solutions
To be honest, I think the support of unicode in Python before Python 3, being totally honest, is a f*knig nightmare. I prefer PHP 5.x support for unicode (= zero support).
One can get just crazy, sometimes things work, sometimes things crash somewhere unexpectly, or they don’t really crash, they just crash when you want to [...]
Serializing native data in Python
For a project I’m currently working on I needed to serialize some structures in Python. The only premise is that they were only made with basic/native Python types, such as lists, dicts, strings, integers, …
The thinkgs I was considering were:
compact representation
fast serialization/deserialization
human-readable / human-editable a must
So after thinking for a while, I found 3 possible [...]
bbcodeutils: BBCode parser and BBCode to HTML for Python
Yesterday I was looking for a Python module able to parse Bulletin Board Code (bbcode for friends) or able to transform bbcode to HTML.
After looking on the Internet I decided to create bbcodeutils a Python module to parse, generate and transform bbcode. I created in a way that I think is really simple to use.
Inside [...]
[SOLVED] Add Unique Constraints to Google App Engine databases
The problem:
Google App Engine rules! The truth is that I’m starting to feel confortable programming in Python, although I still like the curly braces to indentate.
Anyway, the datastore used by Google is superpowerful and supersimple to use, but it has some limitations. With the App Engine SDK you can easily say which attributes you want [...]
Manso Trick: simple strip HTML tags using Python
The idea is to make a simple function that strips all HTML tags on a given string.
I know the following code might not seem the best code in the world, but keep in mind that I’m just looking for a simple function that does the job.
def stripHTMLTags (html):
"""
Strip HTML [...]
How to get user-agent in Google App Engine using Python
User-Agent tells which is the client application that is making the request. It tells if it’s a browser (and information which browser it is), if it’s a robot (for example a Google/Yahoo/Bing spider), … In theory the string is present in all HTTP headers, no matter which client is doing the request, but it might [...]
Max URL (or GET) length in Google App Engine
I’ve done some tests in order to evaluate what is the maximum length of a URL that the different browsers can handle, and I ended up with a restriction on the server-side.
According to the tests I’ve been doing, the maximum length of a URL in Google App Engine is 2048 characters.
So, if you are [...]
GeoIP in Google App Engine
It is surprising to me that Google does not offer any service or method in Google App Engine to get the geographic location from a IP. This is something they have in tons of products, and offering this will be something really simple to do for them. I don’t see why they are not offering [...]

Español