Appel d'un méthode dans une autre classe

Arya Dröttningu Messages postés 581 Date d'inscription   Statut Membre Dernière intervention   -  
 potyrond -
Bonjour,

Je voudrais appeler la méthode d'une classe A depuis une classe B mais impossible j'obtiens toujours l'erreur "A objet has no attribute 'printSymbol' ". Il doit y avoir un truc que j'ai mal compris.....

Fichier a.py
class A : 
	symbol = "X"

	def printSymbol (self, i) :
	    return (self.symbol)



Fichier b.py
from a import *

class B : 
    a = A()

    def maFonction (self) :
        symbol =  self.a.printSymbol(1)
        print (symbol )



Quelqu'un pourrait me dire comment faire ?

1 réponse

potyrond
 
Bonjour.

Tu dois faire une erreur ailleurs (nom de fichier ?), car ton code fonctionne très bien.

b = B()
b.maFonction() # 'X'
0