Fix Python – Django TemplateDoesNotExist?

My local machine is running Python 2.5 and Nginx on Ubuntu 8.10, with Django builded from latest development trunk.
For every URL I request, it throws:

TemplateDoesNotExist at /appname/path appname/template_name.html
Django tried loading these templates, in this order:
* Using loader django.template.loaders.filesystem.function:
* Using loader….

Fix Python – Writing Unicode text to a text file?

I’m pulling data out of a Google doc, processing it, and writing it to a file (that eventually I will paste into a Wordpress page).
It has some non-ASCII symbols. How can I convert these safely to symbols that can be used in HTML source?
Currently I’m converting everything to Unicode on the way in, joining it all together in a Python string, then….

Fix Python – Safest way to convert float to integer in python?

Python’s math module contain handy functions like floor & ceil. These functions take a floating point number and return the nearest integer below or above it. However these functions return the answer as a floating point number. For example:
import math
f=math.floor(2.3)

Now f returns:
2.0

What is the safest way to get an integer out of this flo….

Fix Python – How to get string objects instead of Unicode from JSON?

I’m using Python 2 to parse JSON from ASCII encoded text files.
When loading these files with either json or simplejson, all my string values are cast to Unicode objects instead of string objects. The problem is, I have to use the data with some libraries that only accept string objects. I can’t change the libraries nor update them.
Is it possib….

Fix Python – Setting the correct encoding when piping stdout in Python

When piping the output of a Python program, the Python interpreter gets confused about encoding and sets it to None. This means a program like this:
# -*- coding: utf-8 -*-
print u”åäö”

will work fine when run normally, but fail with:

UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 0: ordinal not in range(128)

when ….

Fix Python – What is the best way to remove accents (normalize) in a Python unicode string?

I have a Unicode string in Python, and I would like to remove all the accents (diacritics).
I found on the web an elegant way to do this (in Java):

convert the Unicode string to its long normalized form (with a separate character for letters and diacritics)
remove all the characters whose Unicode type is “diacritic”.

Do I need to install a libra….