Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python complains that class instance is not defined
#1
Hello. I have this code line:

instruction = Instruction (byte)
that generates the following error message:

Quote:Traceback (most recent call last):
File "emulator.py", line 29, in <module>
main ()
File "emulator.py", line 21, in main
instruction = Instruction (byte)
NameError: global name 'Instruction' is not defined

Instruction code it is:

class Instruction (object):
	def __init___(self, identifier_byte):
		#type: (byte) ->
		self.identifier_byte = identifier_byte
So, what I am fogetting? Thanks for the input.
Quote
#2
Where is the class statement relative to the line causing the error? It looks like the error line is in a function called main. If the class definition is not in the same file before main is called, that could cause the error.
ndc85430 likes this post
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
(Sep-14-2019, 12:54 AM)ichabod801 Wrote: Where is the class statement relative to the line causing the error? It looks like the error line is in a function called main. If the class definition is not in the same file before main is called, that could cause the error.

Thanks, that was the issue (solved with an import).

Nonetheless,now I am receiving a:

Quote:Traceback (most recent call last):
File "emulator.py", line 30, in <module>
main ()
File "emulator.py", line 22, in main
instruction = Instruction (byte)
TypeError: object() takes no parameters


and line 22 it is the same! (since I added an import):
instruction = Instruction (byte)
from the class constructor:

def __init___(self, identifier_byte):
		#type: (byte) ->
		self.identifier_byte = identifier_byte
it seems that it takes a parameter for me.
Quote
#4
You have three underscores after 'init', not two, so it's not overriding the actual initializer from object.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  how to add class instance attributes from list 999masks 2 205 Jul-22-2019, 07:59 AM
Last Post: 999masks
  saving (in text or binary) an object under a defined class cai0824 3 402 May-12-2019, 08:55 AM
Last Post: snippsat
  "not defined" error in function referencing a class Exsul 2 478 Mar-27-2019, 11:59 PM
Last Post: Exsul
  Trying to set an instance variable to current value of a class variable ScottDiesing 3 392 Feb-15-2019, 03:12 PM
Last Post: ScottDiesing
  instance of a class in different files DionisiO 2 325 Jan-21-2019, 09:38 PM
Last Post: DionisiO
  Printing class instance P13N 2 437 Dec-23-2018, 10:28 PM
Last Post: P13N
  How I can create reference to member of the class instance? AlekseyPython 8 576 Dec-05-2018, 06:24 AM
Last Post: AlekseyPython
  Class object instance. Link instance attribute to class. Can it be done easier. Windspar 7 664 Dec-03-2018, 11:16 PM
Last Post: Windspar
  Difference between self and a reference to own class. (unique instance) Dupletor 1 680 Nov-01-2018, 11:14 AM
Last Post: Gribouillis
  Help creating a class instance dynamically Kotevski 9 912 Aug-17-2018, 05:23 AM
Last Post: Gribouillis

Forum Jump:


Users browsing this thread: 1 Guest(s)