You can only call methods on a class without instantiating it, if it are
classmethods.

http://pyref.infogami.com/classmethod

2011/2/28 Christopher Brookes <chris.klai...@gmail.com>

> I don't understand
>
> @classmethod
>     def DisplayAll(cls, herosAll
> ):
>
> What is cls ?
>
> 2011/2/28 Izz ad-Din Ruhulessin <izzaddin.ruhules...@gmail.com>
>
>> @classmethod
>>     def DisplayAll(herosAll):
>>
>> is of course:
>>
>> @classmethod
>>     def DisplayAll(cls, herosAll):
>>
>> 2011/2/28 Izz ad-Din Ruhulessin <izzaddin.ruhules...@gmail.com>
>>
>> Hi, you must pass the herosAll list to the DisplayAll() method like this
>>>
>>> class Character():
>>>     @classmethod
>>>     def DisplayAll(herosAll):
>>>          print ('There is', Character.CharacterCount, 'heros')
>>>         for heros in herosAll:
>>>             heros.DisplayCharacterInfos()
>>>
>>> herosAll = [
>>>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>>>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>>>
>>> Character.DisplayAll(herosAll)
>>>
>>>
>>> 2011/2/28 Christopher Brookes <chris.klai...@gmail.com>
>>>
>>>>  Hi, first sorry for my poor english, i'm a french guy, i'm trying to
>>>> make the best :(
>>>>
>>>> I would like to split my python script into multiples files.
>>>> I want :
>>>> A file which contains only class creations and methods,
>>>> A file with some personals functions
>>>> And a main.py which is the main script.
>>>>
>>>> But i'm getting some problems
>>>> In class creation file, i've a init method which create a character  (it
>>>> works).
>>>> They are created in main.py like this :
>>>>
>>>> herosAll = [
>>>>  Character(1,"Antaa","Soldat moins fort",15,5,8),
>>>>  Character(2,"Klaitos","Soldat moins fort",15,5,8)]
>>>>
>>>> But when i want to display all information about my character with :
>>>>
>>>> class Character():
>>>>     def DisplayAll():
>>>>         print ('There is', Character.CharacterCount, 'heros')
>>>>         for heros in herosAll:
>>>>             heros.DisplayCharacterInfos()
>>>>
>>>> I'm getting :
>>>>
>>>> Traceback (most recent call last):
>>>>   File "main.py", line 28, in <module>
>>>>     Character.DisplayAll()
>>>>   File "/home/christopher/class_creation.py", line 53, in DisplayAll
>>>>     for heros in herosAll:
>>>> NameError: global name 'herosAll' is not defined
>>>>
>>>> I know the source of the problem. The list herosAll is declared in
>>>> main.py so he can't access to it. But i'm stuck here. How can he get it ?
>>>> Have I to append the list in the init method ?
>>>>
>>>> Thank you for ready.
>>>>
>>>>
>>>>
>>>> --
>>>> Brookes Christopher.
>>>>
>>>> _______________________________________________
>>>> Tutor maillist  -  Tutor@python.org
>>>> To unsubscribe or change subscription options:
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>>>
>>>
>>
>
>
> --
> Brookes Christopher.
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to