very strange bug coercing to Unicode: need string or buffer, int found

bussiere maillist bussieremaillist at gmail.com
Wed Jun 21 09:04:00 EDT 2006


i truly didn't understand this error :
Traceback (most recent call last):
  File "D:\Programmation\FrancePaquet\FrancePaquet.py", line 77, in ?
    cabtri = "zz" + chiffrescabtri + clefc
TypeError: coercing to Unicode: need string or buffer, int found
>>>

if someone could help me i will be glad, this program worked yesterday.
Regards
Bussiere

here is my program :

import fileinput,string

def calculclef(nombre):
    nombre2 = int(nombre)*10
    nombre = str(nombre2)
    taille = len(nombre)
    compteur = 0
    nombrepair = 0
    nombreimpair = 0
    compteur = taille - 2
    while compteur != -1:
        print 'nombre :'
        print nombre[compteur] + '\n'
        if  compteur%2 :
            nombrepair = nombrepair + int(nombre[compteur])
            print 'suite pair %d' % nombrepair
        else:
            nombreimpair = nombreimpair + int(nombre[compteur])
            print 'suite impair %d' % nombreimpair
            print
        compteur = compteur - 1
    print nombreimpair
    print nombrepair
    clef = nombrepair*3+nombreimpair
    clef  = 10-(clef%10)
    if clef == 10:
        clef = 0
    return clef

compteclient = "8150"
souscompteclient = "03"
codeaffranc = "080"
partielibre = "142391"

print("LES CODES POSTAUX DOIVENT ETRE A LA FIN DU FICHIER CSV ! \n")
fichA=raw_input("Entrez le nom du fichier d'entree : ")
print ("\n")
fichC=raw_input("Entrez le nom du fichier de sortie : ")
print ("\n")
debutplage = raw_input("Entrez le numero du debut de plage : ")
print ("\n")
finplage = raw_input("Entrez le numero de fin de plage : ")
print ("\n")

nbredeplage = int(debutplage) - int(finplage)

fiA=open(fichA,"r")
fiC=open(fichC,"w")
print calculclef(debutplage)
compteur = 0
debutplage
while 1:
    fileencoding = "latin1"
    ligneA=fiA.readline()
    ligneA = ligneA.decode(fileencoding)



    if ligneA == "":

        break

    if ligneA != "":
        stramettre = ligneA
        if compteur != 0:
            taille = len(ligneA)
            codepostal = ligneA[taille-5] + ligneA[taille-4] +
ligneA[taille-3] + ligneA[taille-2]+ ligneA[taille-1]
            print codepostal
            clefb = calculclef(debutplage)
            clefb = str(clefb)
            print clefb
            num = str(debutplage)
            cabsuivis = "8w"+ num + clefb
            stramettre = stramettre  + ";*" + cabsuivis + "*"
            chiffrescabtri =  clefb + codepostal + compteclient +
souscompteclient + codeaffranc + partielibre
            clefc = calculclef(chiffrescabtri)
            cabtri = "zz" + chiffrescabtri + clefc
            stramettre = stramettre  + ";*" + cabtri + "*"


        fiC.write(stramettre)
        compteur += 1

        print compteur, "\n"


print "FINIT"
fiA.close()
fiC.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060621/2789aed6/attachment.html>


More information about the Python-list mailing list