Unbound Method Error

Piet van Oostrum piet at cs.uu.nl
Tue Jun 9 10:36:02 CEST 2009


>>>>> "Enrico" <4564 at 755189.45> (E) wrote:

>E> "lczancanella" <lczancanella at gmail.com> ha scritto nel messaggio
>E> news:32bf5ccb-5bfd-49a5-b423-9d41180a0ddb at l28g2000vba.googlegroups.com...
>>> Hi, i am brand new in Python, so sorry if this question is too basic,
>>> but i have tried a lot and dont have success... I have the following
>>> code...
>>> 
>>> class Funcoes:
>>> def CifradorDeCesar(mensagem, chave, funcao):

>E> A quick look to your code suggests to me to rewrite the above lines as:

>E> class Funcoes:
>E>     @classmethod
>E>     def CifradorDeCesar(self, mensagem, chave, funcao):

>E> @classmethod is needed since you call:
>>> atribdescripto = Funcoes.CifradorDeCesar (atribcripto,
>E> 3, 2)

The method doesn't need the class at all, so a staticmethod would be
preferable:
class Funcoes:
    @staticmethod
    def CifradorDeCesar(self, mensagem, chave, funcao):

But as been mentioned in this thread before, there might be no reason to
use the class anyway.

The next thing you will run into is that you call CifradorDeCesar with
an int as parameter (mensagem) but it expects a string (or byte string,
at least something iterable).

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list