Here it is the script that is working for me.
This was done thanks to this great pages
(http://effbot.org/zone/unicode-objects.htm) it took me 3 days to find
it on internet.
Thank you google  and of course thank you to the author :-)


# -*- coding: utf8 -*-
import os,codecs
from django.models.announceManager import *
import re
os.chdir(os.path.abspath("E:\\instal\\django\\view_servicealapersonne\\votreservice\\_initialLoad"))
f = open("departments.txt")
regexobj = re.compile("([0-9]+)\s+([\w\s?]+)",re.UNICODE)


for l in f.readlines():
    fileencoding = "iso-8859-1"
    txt = l.decode(fileencoding)
    print "the current line is :"+txt.encode(fileencoding, "replace")
    try:
        matches = regexobj.search(txt).groups()
    except:
        print "this is an empty line"
    print "matches " +str(matches)
    r
=Department(department=matches[1].encode('utf-8','replace'),department_number=matches[0].encode('utf-8'),country="France")
    r.save()
    print "ok"
    print r
    
f.close()


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to