Hi all,
I am working on a problem that should have been very trivial but has turned into a multiple marathon without an end in sight. I have written two very small scripts, one auxiliary script as below with two classes 'Node' and 'Queue' intended for use in a linked list.
class Node:
value=None
nextNode=None
def __init__(self,v):
self.value=v
class Queue:
dummy=Node(None)
dummy.nextNode=None # Kan ifrågasättas map nödvändighet, sker redan i Node-instantieringen...
front=None
back=None
def __init__(self):
self.front=self.dummy
self.back=self.dummy
self.p=self.dummy
def show(self):
p=self.back
while p!=None:
print p.value
p=p.nextNode
print "\n"
print
def isEmpty(self):
if self.back==None:
return True
else:
return False
def put(self,v):
x=Node(v)
x.nextNode=self.back
self.back=x
def get(self):
if self.back.nextNode!=None:
p=self.back
while p.nextNode!=None:
p=p.nextNode
x=p
self.front=p
self.front.value=None
self.front.nextNode=None
return x
else:
print 'Cannot access an empty queue.'
return None
The main program peruses the classes of the auxiliary script, as seen below
from Queue import *
Snake=Queue()
x = 5
while x !=4:
print '\n'
print '1. Add'
print '2. Remove'
print '3. Check if Queue is empty'
print '4. Terminate program.'
x = input()
if x == 1:
## print x
str = raw_input("Enter a string ")
Snake.put(str)
print "Funcion put successful"
else:
print "No one..."
Snake.show()
But whatever I try, and I have now tried a very great many different angles, I keep getting the error message
Traceback (most recent call last):
File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
exec codeObject in __main__.__dict__
File "C:\Python24\Lib\site-packages\pythonwin\lab4uppg2.py", line 24, in ?
Snake.show()
AttributeError: Queue instance has no attribute 'show'
D%#¤ straight Queue has an attribute 'show', it's plain to see, I put it there. And so would its instance Snake if there were any good sense. The method 'put' can be referenced, so it's just 'show' that's being bullied for no reason, not even a bad reason. The line 'from Queue import *' in the header should see that everything is included. (The file in which the classes are IS named Queue.py).
Does 'import' have a bug, or is PythonWin unstable? Rumor is PythonWin does not always take data file updates into account. If this is so, then PythonWin really is a crock without a future.
VERY grateful for any help. I am becoming a MAJOR ulcer sufferer.