triptoe
September 4th, 2007, 10:28 PM
my question is... when I fire up the interactive python interpreter... i import my file but it doesn't work right. for instance here is my code:
#! /usr/bin/env python
# linked lists
class Node:
def __init__(self, cargo=None, next=None):
self.cargo = cargo
self.next = next
def __str__(self):
return str(self.cargo)
node = Node("test")
print node
when i type at the commandline: python
and then it brings up the interpreter... then i type: import nodes (the filename is nodes.py)
it prints test correctly. However when i try to interact with it like declare another node:
node1 = Node(1) it screams at me and tells me Node is undefined
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nodes
test
>>> node1 = Node(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Node' is not defined
>>>
#! /usr/bin/env python
# linked lists
class Node:
def __init__(self, cargo=None, next=None):
self.cargo = cargo
self.next = next
def __str__(self):
return str(self.cargo)
node = Node("test")
print node
when i type at the commandline: python
and then it brings up the interpreter... then i type: import nodes (the filename is nodes.py)
it prints test correctly. However when i try to interact with it like declare another node:
node1 = Node(1) it screams at me and tells me Node is undefined
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nodes
test
>>> node1 = Node(1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Node' is not defined
>>>