[Tutor] Setting a global variable on class initialisation

Max Russell max.russell at barco.com
Fri Apr 28 10:46:20 CEST 2006

Hello again
Sorry I didn't make the problem I'm working with all too clear. Basically
I'm working with a class (Directory) that upon creation reads in a 3 files
and from these files populates one main list.
This bit is fine.
The trickier bit was that I need to use two of the sublists (e.g the
contents of two of the files) outwith the module. I didn't want to read the
lists in again as I wanted the data to be set at the time the Directory
class is created. The lists are accessed from other classes and although I
tried passing the instance of Directory into the new class (Item) but this
was causing real problems Item was trying to read in the lists:
def __init__(self, filename, **args):
I noted that I couldn't put my argument for an instance of Directory after
**args (presumably because **args is used to mop up the remaining arguments
as a list) and when I put it before it messed up the reading of the list.
So my code now has this format-
    def GetCategories(self):

        #Assign the list values read in via platformCategories and

        global platformCategories
        platformCategories = self.GetPlatformsFile()
        global typeCategories
        typeCategories = self.GetTypesFile()
The method above is within Directory and updates the two lists with the
values I need. (The methods called within GetCategories do the returning of
the lists.)
I think I've got a grasp on what was going wrong.
Max Russell
Senior Test Engineer<?XML:NAMESPACE PREFIX = O /> 

Bonnington Bond, 2 Anderson Place, Edinburgh EH6 5NP, UK
Tel + 44 (0) 131 472 5731 Fax + 44 (0) 131 472 4799
max.russell at barco.com <mailto:max.russell at barco.com> 

Unless indicated otherwise, the information contained in this message is
privileged and confidential, and is intended only for the use of the
addressee(s) named above and others who have been specifically authorized to
receive it. If you are not the intended recipient, you are hereby notified
that any dissemination, distribution or copying of this message and/or
attachments is strictly prohibited. The company accepts no liability for any
damage caused by any virus transmitted by this email. Furthermore, the
company does not warrant a proper and complete transmission of this
information, nor does it accept liability for any delays. If you have
received this message in error, please contact the sender and delete the
message. Thank you. 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060428/d2cfd86a/attachment.htm 

More information about the Tutor mailing list