Python Forum
NameError: NameError: global name 'BPLInstruction' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NameError: NameError: global name 'BPLInstruction' is not defined
#1
Hello I am receiving these messages when running my code:

Error:
File "/home/leopoldo/cpu.py", line 28, in process_instructions instruction = self.identify_instruction (byte) File "/home/leopoldo/cpu.py", line 18, in identify_instruction instruction = BPLInstruction (byte) NameError: global name 'BPLInstruction' is not defined
The code:

def process_instructions (self):
		counter=0
		for byte in self.rom.data_bytes:
			byte = self.rom.get_byte (self.pc)
			instruction = self.identify_instruction (byte)
			if instruction is None:
				raise Exception ("Instruction not found")
			instruction.process ()
			print ("self.pc, antes: ", self.pc)
			self.pc+= instruction.instruction_length
			print ("counter: ", counter)
			print ("self.pc, depois: ", self.pc)
			print ("")
			counter = counter + 1
def identify_instruction (self, byte):
		if byte==0x78:	
			instruction = LDAInstruction (byte)
		elif byte==0xD8:
			instruction = SEIInstruction (byte)
		elif byte==0xA9:
			instruction = CLDInstruction (byte)
		elif byte==0x10:
			instruction = BPLInstruction (byte)
		else:
			instruction = None
		return instruction
class LDAInstruction (Instruction):
	def process (self):
		print ("Identifier Byte: LDAInstruction:",hex (self.identity_byte), self.identity_byte )
	instruction_length = 2

class SEIInstruction (Instruction):
	def process (self):
		print ("Identifier Byte: SEIInstruction:",hex (self.identity_byte), self.identity_byte)
	instruction_length = 1

class CLDInstruction (Instruction):
	def process (self):
		print ("Identifier Byte: CLDInstruction:",hex (self.identity_byte), self.identity_byte)
	instruction_length = 1

class BPLinstruction (Instruction):
	def process (self):
		print ("Identifier Byte: BPLinstruction:",hex (self.identity_byte), self.identity_byte)
	instruction_length = 1
I can't identify the source of trouble because I see no difference between the code related to BPL, whether is its class definition or its elif clause on "identify_instruction" to the others instruction's code.

So I don't see what is not defined there, especially when python does not complain about any other instruction. Thanks for the help.
Reply


Messages In This Thread
NameError: NameError: global name 'BPLInstruction' is not defined - by colt - Oct-20-2019, 11:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 173 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Getting NameError for a function that is defined JonWayn 2 1,057 Dec-11-2022, 01:53 PM
Last Post: JonWayn
Question Help with function - encryption - messages - NameError: name 'message' is not defined MrKnd94 4 2,776 Nov-11-2022, 09:03 PM
Last Post: deanhystad
  NameError nafshar 3 943 Oct-18-2022, 02:13 PM
Last Post: deanhystad
  NameError: azizrasul 12 1,807 Oct-02-2022, 03:15 AM
Last Post: azizrasul
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,205 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,457 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  Why the NameError? Mark17 4 1,905 May-17-2022, 08:14 PM
Last Post: Mark17
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 1,865 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,186 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020