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

2006-06-21 Thread bussiere maillist
i truly didn't understand this error :Traceback (most recent call last): File D:\Programmation\FrancePaquet\FrancePaquet.py, line 77, in ? cabtri = zz + chiffrescabtri + clefcTypeError: coercing to Unicode: need string or buffer, int found
 if someone could help me i will be glad, this program worked yesterday.RegardsBussierehere is my program :import fileinput,stringdef 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 clefcompteclient = 8150souscompteclient = 03codeaffranc = 080partielibre = 142391print(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 = 0debutplagewhile 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, \nprint FINITfiA.close()fiC.close()
-- 
http://mail.python.org/mailman/listinfo/python-list

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

2006-06-21 Thread Max Erickson
bussiere maillist [EMAIL PROTECTED] wrote:

 --=_Part_118629_1441854.1150895040355
 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

 
 def calculclef(nombre):
 if clef == 10:
 clef = 0
 return clef
 

 clefb = calculclef(debutplage)
 clefb = str(clefb)
 print clefb

 clefc = calculclef(chiffrescabtri)

 cabtri = zz + chiffrescabtri + clefc


Your calculclef function returns an integer. You explitly convert 
clefb into a string, but you never convert clefc into a string, hence 
the TypeError.

max

-- 
http://mail.python.org/mailman/listinfo/python-list