Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Problème Héritage Classe + Surchage fonction

2 réponses
Avatar
Didier FRAISSE
Bonjour à tous

je débute en POO et j'ai un (petit) problème

un extrait de mon code

class EtatFamille():
def get_ligne(self,row):
return ((row[1].strip()),
(row[2].strip()),
(row[3].strip()),
(row[4].strip()),
(row[5].strip()),
(row[6].strip()),
(row[7].strip()),
(row[8].strip()),
(row[9].strip()),
(row[10].strip()),
(row[11].strip()),
(row[12].strip()),
'',
(row[13].strip()),
)

def generer_xls(self,info,repertoire):
self.wkb = excel.Workbooks.Add()
code = ''
indice = 0
reader = csv.reader( file(self.txtfile), dialect='excel',
delimiter=';')
for row in reader:
Sheet.Range(Sheet.Cells(ligne,1),Sheet.Cells(ligne,14)).Value =

self.get_ligne(row)

class EtatRepresentantFamille(EtatFamille):
def get_ligne(self,row):
return ((row[2].strip()),
(row[3].strip()),
(row[4].strip()),
(row[5].strip()),
(row[6].strip()),
(row[7].strip()),
(row[8].strip()),
(row[9].strip()),
(row[10].strip()),
(row[11].strip()),
(row[12].strip()),
(row[13].strip()),
''
(row[14].strip()),
)

lorsque j'utilise la classe EtatRepresentantFamille, j'obtiens l'erreur

File "C:\Scripts GFD\StatComm.pyw", line 338, in get_ligne
return ((row[2].strip()),
TypeError: object of type 'str' is not callable

Il semble qu'il considère row comme une chaine et non plus comme une liste.

Quelqu'un peut-il m'expliquer pourquoi et comment résoudre le problème

Merci d'avance
Didier

2 réponses

Avatar
Eric Brunel
Didier FRAISSE wrote:
Bonjour à tous

je débute en POO et j'ai un (petit) problème

un extrait de mon code

class EtatFamille():
def get_ligne(self,row):
return ((row[1].strip()),
(row[2].strip()),
(row[3].strip()),
(row[4].strip()),
(row[5].strip()),
(row[6].strip()),
(row[7].strip()),
(row[8].strip()),
(row[9].strip()),
(row[10].strip()),
(row[11].strip()),
(row[12].strip()),
'',
(row[13].strip()),
)

def generer_xls(self,info,repertoire):
self.wkb = excel.Workbooks.Add()
code = ''
indice = 0
reader = csv.reader( file(self.txtfile), dialect='excel',
delimiter=';')
for row in reader:
Sheet.Range(Sheet.Cells(ligne,1),Sheet.Cells(ligne,14)).Value > self.get_ligne(row)

class EtatRepresentantFamille(EtatFamille):
def get_ligne(self,row):
return ((row[2].strip()),
(row[3].strip()),
(row[4].strip()),
(row[5].strip()),
(row[6].strip()),
(row[7].strip()),
(row[8].strip()),
(row[9].strip()),
(row[10].strip()),
(row[11].strip()),
(row[12].strip()),
(row[13].strip()),
''


Il manque une virgule à la fin de cette ligne...

(row[14].strip()),
)

lorsque j'utilise la classe EtatRepresentantFamille, j'obtiens l'erreur

File "C:Scripts GFDStatComm.pyw", line 338, in get_ligne
return ((row[2].strip()),
TypeError: object of type 'str' is not callable

Il semble qu'il considère row comme une chaine et non plus comme une liste.

Quelqu'un peut-il m'expliquer pourquoi et comment résoudre le problème


HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Avatar
David Douard
Didier FRAISSE wrote:

Bonjour à tous

je débute en POO et j'ai un (petit) problème

un extrait de mon code

class EtatFamille():
def get_ligne(self,row):
return ((row[1].strip()),
(row[2].strip()),
(row[3].strip()),
(row[4].strip()),
(row[5].strip()),
(row[6].strip()),
(row[7].strip()),
(row[8].strip()),
(row[9].strip()),
(row[10].strip()),
(row[11].strip()),
(row[12].strip()),
'',
(row[13].strip()),
)


Bonjour,

permettez-moi de réagir à ce code. Ca me fait mal aux doigts...
On pourrait plutôt faire qqchose comme :

def get_ligne(self, row):
return tuple([(x.strip()) for x in row[1:14]].insert(-1, ''))

Il y aussi la possibilité d'utiliser un 'map' mais il semble qui Guido
conseille de ne pas utiliser le 'map' (sauf cas particuliers).

David