Hi all,
I have the following class code for a Node for a Linked List, (saved in
node.py)
class Node :
def __init__(self,element):
self.element = element
self.next = None
then i have another module called LinkedList.py, with following code
import sys
import node
def main():
print "Does nothin ATM, as it doesnt work"
main()
the problem im having is that im getting NameError exception when i run
LinkedList.py "global name 'Node' is not defined"
Does anyone know what the problem is here?
Thanks in advance 4 2130
placid wrote: I have the following class code for a Node for a Linked List, (saved in node.py)
class Node : def __init__(self,element): self.element = element self.next = None
then i have another module called LinkedList.py, with following code
import sys import node def main(): print "Does nothin ATM, as it doesnt work" main()
the problem im having is that im getting NameError exception when i run LinkedList.py "global name 'Node' is not defined"
Does anyone know what the problem is here?
I have trouble believing you. I suspect you are telling us what you
think is happening, and leaving something vital out. In particular,
cut and paste the traceback.
Here's another experiment, interactively do:
import node
print node.__file__
Perhaps that will tell you something.
--Scott David Daniels sc***********@acm.org
Scott David Daniels wrote: placid wrote: I have the following class code for a Node for a Linked List, (saved in node.py)
class Node : def __init__(self,element): self.element = element self.next = None
then i have another module called LinkedList.py, with following code
import sys import node def main(): print "Does nothin ATM, as it doesnt work" main()
the problem im having is that im getting NameError exception when i run LinkedList.py "global name 'Node' is not defined"
Does anyone know what the problem is here? I have trouble believing you. I suspect you are telling us what you
im not leaving anything out, im telling you what's happening
think is happening, and leaving something vital out. In particular, cut and paste the traceback.
here it is!
Traceback (most recent call last):
File "LinkedList.py", line 7, in ?
main()
File "LinkedList.py", line 4, in main
n = Node("test")
NameError: global name 'Node' is not defined Here's another experiment, interactively do:
import node print node.__file__
import node print node.__file__
node.py Perhaps that will tell you something.
More information, im using Windows XP Pro, these two files are in same
directory... --Scott David Daniels sc***********@acm.org
so there is a record of this problem i had, to solve this problem
either use
import node
Dennis Lee Bieber wrote: On 10 Apr 2006 20:55:31 -0700, "placid" <Bu****@gmail.com> declaimed the following in comp.lang.python:
Traceback (most recent call last): File "LinkedList.py", line 7, in ? main() File "LinkedList.py", line 4, in main n = Node("test") NameError: global name 'Node' is not defined
That is NOT the same code as you posted.
You posted: import sys import node
def main(): print "Does nothin ATM, as it doesnt work"
main()
Line 4 of that is "def main():"
If you have any .pyc or .pyo files in the same directory as your source, delete them, try again, and show us what happened.
BTW: as for the code that is being run... IT NEEDS
n = node.Node("test")
You imported a module "node", but the class definition named "Node" is INSIDE the module -- so you have to specify module.class to access it... -- > ================================================== ============ < > wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > wu******@dm.net | Bestiaria Support Staff < > ================================================== ============ < > Home Page: <http://www.dm.net/~wulfraed/> < > Overflow Page: <http://wlfraed.home.netcom.com/> <
Sorry, i left some code out, my bad, LinkedList.py contains (well it
doesnt anymore, but originally did)
import node
def main():
n = Node("Test")
print n.element
main()
but now i know why this doesnt work and the solution (see previous post
of mine)
thanks for all the help! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Steve Holden |
last post by:
This is even stranger: it makes it if I import the module a second time:
import dbimp as dbimp
import sys
if __name__ == "__main__":
dbimp.install()
#k = sys.modules.keys()
#k.sort()
#for...
|
by: Olivier Noblanc ATOUSOFT |
last post by:
Hello,
When i want to import a .py fire from another subdirectory i make
import inc/setupxml
but that make me an error message.
|
by: David Berry |
last post by:
Hi All. I'm looking for any help or sample code that can show me how to make a file import wizard in ASP.NET (VB preferred) like the one that MS Access uses. I'm working on a web site where the...
|
by: Robin Becker |
last post by:
Whilst testing the excellent xlrd http://www.python.org/pypi/xlrd/0.3a1
I came across the following strangeness when trying to add an import of os to
assist with debugging/tracing.
At line 66...
|
by: Dan |
last post by:
Could someone please help me with auto importing a series of data
files into an Access table. I tried to follow code given below in a
previous messagebut i'm getting error messages.
Here's my...
|
by: khutch |
last post by:
Not that up on MS Access. I understand that the TransferText command
can be used to import csv files into a database. Question: Does the
text file have to mirror the alignment of the table columns...
|
by: Nick M |
last post by:
Hello All,
Excellent info here Thanks!
I am very new to using access in general and I am on a learning curve.
I'm trying to import an excel workbook (with worksheets) into an access db
via a...
|
by: Ron Adam |
last post by:
from __future__ import absolute_import
Is there a way to check if this is working? I get the same results with or
without it.
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17)
on win 32
...
|
by: Stef Mientki |
last post by:
hello,
The import statement "import sqlite3" gives the error given below.
In simple programs, the import statement (sometimes) succeed,
and I can indeed access the database.
So I guess there is...
|
by: rsoh.woodhouse |
last post by:
Hi,
I'm trying to work out some strange (to me) behaviour that I see when
running a python script in two different ways (I've inherited some
code that needs to be maintained and integrated with...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |