Python – csv with different encoding

csvencodingpython

Possible Duplicate:
Open a file in the proper encoding automatically

my code:

import csv

def handle_uploaded_file(f):
  dataReader = csv.reader(f, delimiter=';', quotechar='"')

for row in dataReader:
  do_sth

the problem is that it works well only if csv is UTF-8 encoded. What should I change to serve the iso-8859-2 or windows-1250 encoding?
(the best solution is to autorecognize the encoding, but hand converting is also acceptable)

Best Answer

The solution for now:

def reencode(file):
    for line in file:
        yield line.decode('windows-1250').encode('utf-8')

csv_reader = csv.reader(reencode(open(filepath)), delimiter=";",quotechar='"')