A scoping question

Premshree Pillai premshree.pillai at gmail.com
Tue Dec 28 15:10:16 EST 2004


On Tue, 28 Dec 2004 19:59:01 GMT, It's me <itsme at yahoo.com> wrote:
> 
> "Premshree Pillai" <premshree.pillai at gmail.com> wrote in message
> news:mailman.8524.1104263434.5135.python-list at python.org...
> > On Tue, 28 Dec 2004 19:34:36 GMT, It's me <itsme at yahoo.com> wrote:
> > > This must be another newbie gotchas.
> > >
> > > Consider the following silly code, let say I have the following in
> file1.py:
> > >
> > > #=============
> > > import file2
> > > global myBaseClass
> > > myBaseClass = file2.BaseClass()
> > > myBaseClass.AddChild(file2.NextClass())
> > > #=============
> >
> > You have declared myBaseClass to be global, but it doesn't exist.
> >
> 
> No, myBaseClass exists in file1.py.   The question is how can I tell

Umm, from the sample code (for file2.py) that you provided, I don't
see myBaseClass. You've only declared it to be global in file2.py, but
it does not exist -- does not exist in the sense that it has no type
associated with it, which in turn means meaning you cannot apply
methods to it.

> file2.py that the global variable is in file1 (without doing a silly
> file1.myBaseClass....
> 
> Since I am invoking file2 from file1, I would have thought that global
> variables in file1 exists automatically....(too much C thinking, I know)
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Premshree Pillai
http://www.livejournal.com/~premshree



More information about the Python-list mailing list