Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3119 connectés 

  FORUM HardWare.fr
  Programmation
  Python

  Unbound methods

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Unbound methods

n°844965
masklinn
í dag viðrar vel til loftárása
Posté le 08-09-2004 à 13:08:57  profilanswer
 

imaginons

Code :
  1. class foo:
  2.     def bar(self):
  3.          blabla
  4. [...]


 
faire un fb = foo() me permet d'appeler fb.bar()
 
Mais est-il possible d'appeler cette fonction par foo.bar() (donc sans l'avoir rattachée à une instance de foo)?
J'ai tenté sans paramètre self, sans succès, j'ai tenté en lui fournissant une instance de foo en paramètre self, mais elle l'utilise pour se binder...


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
mood
Publicité
Posté le 08-09-2004 à 13:08:57  profilanswer
 

n°844973
Taz
bisounours-codeur
Posté le 08-09-2004 à 13:25:33  profilanswer
 

ben si tu mets self, c'est une méthode d'instance
 
sinon voir classmethod/staticmethod

n°844975
masklinn
í dag viðrar vel til loftárása
Posté le 08-09-2004 à 13:28:12  profilanswer
 

Taz a écrit :

ben si tu mets self, c'est une méthode d'instance


Je sais, mais sans le self il me balance

Code :
  1. >>> class foo:
  2. ...     def bar():
  3. ...             print 1
  4. ...
  5. >>> foo.bar()
  6. Traceback (most recent call last):
  7.   File "<stdin>", line 1, in ?
  8. TypeError: unbound method bar() must be called with foo instance as first argument (got nothing instead)


Code :
  1. sinon voir classmethod/staticmethod


Ok, j'essaierais de voir ce truc


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°844976
Taz
bisounours-codeur
Posté le 08-09-2004 à 13:31:48  profilanswer
 

ou alors les décorator si tu bosses avec python2.4

n°844983
masklinn
í dag viðrar vel til loftárása
Posté le 08-09-2004 à 13:36:50  profilanswer
 

2.3.4 pour le moment
 
tu pourrais m'en dire plus sur les décorators ou tu m'envoies dans les docs?


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
n°844988
Taz
bisounours-codeur
Posté le 08-09-2004 à 13:38:51  profilanswer
 

ben tu vas sur python.org


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Python

  Unbound methods

 

Sujets relatifs
mais pourquoi :( unbound variable... scheme 
Plus de sujets relatifs à : Unbound methods


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)