Naive question
Duncan Smith
buzzard at urubu.freeserve.co.uk
Mon Jun 19 20:47:39 EDT 2000
I run the following script (Test2.py), query f.id at the command-line prompt
and get NameError: f.
def start():
f = Forest()
class Forest:
def __init__(self):
self.name = 'Forest'
self.id = 1
self.graphs = []
self.count = 0
self.d = DiGraph('initial', self)
class DiGraph:
def __init__(self, label, pForest):
self.owner = pForest
self.name = label
self.id = pForest.count
pForest.graphs.append(self.id)
pForest.count = pForest.count + 1
>>> from Test2 import *
>>> start()
>>> f.id
Traceback (innermost last):
File "<interactive input>", line 1, in ?
NameError: f
>>>
If I comment out the first two lines and create the Forest instance at the
command line, then I can query f.id etc.
#def start():
# f = Forest()
class Forest:
def __init__(self):
self.name = 'Forest'
self.id = 1
self.graphs = []
self.count = 0
self.d = DiGraph('initial', self)
class DiGraph:
def __init__(self, label, pForest):
self.owner = pForest
self.name = label
self.id = pForest.count
pForest.graphs.append(self.id)
pForest.count = pForest.count + 1
>>> from Test2 import *
>>> f=Forest()
>>> f.id
1
>>> f.d.owner.id
1
>>>
How can I achieve this without creating the Forest instance at the command
line? Cheers. Any help appreciated.
Duncan
More information about the Python-list
mailing list