[Tutor] Multiples python files
Izz ad-Din Ruhulessin
izzaddin.ruhulessin at gmail.com
Mon Feb 28 15:01:29 CET 2011
@classmethod
def DisplayAll(herosAll):
is of course:
@classmethod
def DisplayAll(cls, herosAll):
2011/2/28 Izz ad-Din Ruhulessin <izzaddin.ruhulessin at 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.klaitos at 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 at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110228/2a85c892/attachment-0001.html>
More information about the Tutor
mailing list