Title: RE: A scoping question
> myBaseClass.AddChild(file2.NextClass())
> [snip]
> class NextClass:
> def __init__(self):
> for eachChild in myBaseClass.MyChilds: # <- ERROR
> ...
I never assumes globals in my classes. always pass them as param
It's me wrote:
#=
import file2
global myBaseClass
myBaseClass = file2.BaseClass()
myBaseClass.AddChild(file2.NextClass())
#=
[snip]
#=
global myBaseClass
class BaseClass:
def __init__(self):
self.MyChilds = []
...
def AddChild(NewChild):
Thanks, Steve.
So, global is only to within a module (I was afraid of that). Those words
flashed by me when I was reading it but since the word "module" didn't
translate to "file" in my C mind, I didn't catch that.
In that case, you are correct that I have to do an import of file1 in file2.
Not
It's me wrote:
This must be another newbie gotchas.
Consider the following silly code
[snip tightly coupled code]
A few options that also might work better than such tightly coupled modules:
file1.py
import file2
myBaseClass = file2.BaseClass()
class NextCl
It's me 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())
#=
and in file2.py, I have:
#==
On Tue, 28 Dec 2004 19:59:01 GMT, It's me <[EMAIL PROTECTED]> wrote:
>
> "Premshree Pillai" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Tue, 28 Dec 2004 19:34:36 GMT, It's me <[EMAIL PROTECTED]> wrote:
> > > This must be another newbie gotchas.
> > >
> > > Consider the fol
"Premshree Pillai" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Tue, 28 Dec 2004 19:34:36 GMT, It's me <[EMAIL PROTECTED]> wrote:
> > This must be another newbie gotchas.
> >
> > Consider the following silly code, let say I have the following in
file1.py:
> >
> > #=
On Tue, 28 Dec 2004 19:34:36 GMT, It's me <[EMAIL PROTECTED]> 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.AddCh
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())
#=
and in file2.py, I have:
#=
global