Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Object cannot find its attribute
#1
Hello, I have this line of code

print ("Identifier Byte: {}".format(self.identity_byte))
that generates this output:
Quote:120
216
169
Traceback (most recent call last):
File "emulator.py", line 19, in <module>
main ()
File "emulator.py", line 16, in main
cpu.process_instructions ()
File "/home/leopoldo/cpu.py", line 17, in process_instructions
instruction.process ()
File "/home/leopoldo/instruction.py", line 14, in process
print ("Identifier Byte: {}".format(self.identity_byte))
AttributeError: 'Instruction' object has no attribute 'identity_byte'

Then I created this self contained example to show it better:

import argparse
from abc import ABCMeta, abstractmethod

class Instruction (object):
	__metaclass_ = ABCMeta
		
	def __init__ (self,identification_byte):
		identity_byte = identification_byte

	def test (self):
		print ("BOTO")

	@abstractmethod
	def process (self):
		print ("Identifier Byte: {}".format(self.identity_byte))

	@abstractmethod
	def process2 (self):
		print ("Identifier Byte2: ", self.identity_byte)
		

class LDAInstruction (Instruction):
	def process (self):
		super.process ()

	def process2 (self):
		super.process()

HEADER_SIZE = 16
KB_SIZE = 16384

class ROM (object) :
	def __init__ (self, rom_bytes): 
		self.header = rom_bytes [0:HEADER_SIZE]
		self.num_prg_blocks = self.header [4]
		self.data_bytes = rom_bytes [HEADER_SIZE:HEADER_SIZE + (16 + KB_SIZE * self.num_prg_blocks)]
		self.total_size = 16 + KB_SIZE * self.num_prg_blocks

	def get_byte (self, pc):
		return	(self.data_bytes [pc])

from rom import ROM
from instruction import Instruction

class CPU (object):
	def __init__(self, rom_bytes):
		self.registers = []
		self.rom = ROM (rom_bytes)
		self.pc = 0

	def process_instructions (self):
		for byte in self.rom.data_bytes:
			byte = self.rom.get_byte (self.pc)

			self.pc+=1
			print (byte)
			if (byte == 169):
				instruction = Instruction (byte)
				instruction.process ()
				instruction.process2 ()
			if (self.pc == 3):
				break


def main ():

	parser = argparse.ArgumentParser (description='NES EMULATOR'); 
	parser.add_argument ('rom_path',metavar='R',type=str,help='path to the rom')
	args=parser.parse_args()

	with open (args.rom_path, 'rb') as file:
		rom_bytes = file.read ()			

	cpu = CPU(rom_bytes)
	cpu.process_instructions ()

if __name__ == '__main__':
	main () 
I do not know why its complaining about the lack of the 'identity_byte' attribute, which is clearly present. So what I am doing wrong/ Thanks for the support
Quote
#2
(Sep-29-2019, 11:48 PM)colt Wrote: I do not know why its complaining about the lack of the 'identity_byte' attribute, which is clearly present.

Looks pretty not present to me. You need to assign to self.identity_byte on line 8.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#3
(Sep-30-2019, 12:30 AM)ichabod801 Wrote:
(Sep-29-2019, 11:48 PM)colt Wrote: I do not know why its complaining about the lack of the 'identity_byte' attribute, which is clearly present.

Looks pretty not present to me. You need to assign to self.identity_byte on line 8.

True. Nonetheless, the problem persists (same error message).
Quote
#4
I cannot replicate your problem. I can't run all of your code, since I don't have ROM data or anything. But, if I load your classes and do this:

    instruction = Instruction(b'X')
    instruction.process()
    instruction.process2()
It works fine. Can you simplify your code to a more runnable snippet that replicates your problem?
colt likes this post
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#5
Note that __metaclass_ on line 5 is missing one underscore
Quote
#6
(Oct-06-2019, 01:59 AM)ichabod801 Wrote: I cannot replicate your problem. I can't run all of your code, since I don't have ROM data or anything. But, if I load your classes and do this:

    instruction = Instruction(b'X')
    instruction.process()
    instruction.process2()
It works fine. Can you simplify your code to a more runnable snippet that replicates your problem?

I tried with
instruction = Instruction(b'X')
and received:
Quote: File "test.py", line 55
instruction = Instruction (b 'X')
^
SyntaxError: invalid syntax

The "^" is showing after the 'X' here, not in the beggining of instruction
and to answer your question, unfortunately I don't. I need the data that it is contained on the file and don't know how to replace it.
Quote
#7
Output:
>>> b'X' 'X' >>> b 'X' File "<stdin>", line 1 b 'X' ^ SyntaxError: invalid syntax
Well, if you can't come up with a smaller version of your code that shows the error, I can't help you.
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
  AttributeError: 'top_block_sptr' object has no attribute 'change_param_1' Hadad 2 221 Oct-01-2019, 06:33 PM
Last Post: Hadad
  'Client' object has no attribute 'send_message Bambob01 1 439 Sep-27-2019, 01:40 AM
Last Post: Bambob01
  Reading DBF files from Amazon s3 throwing error - 'int' object has no attribute 'isa abeesm 1 190 Sep-22-2019, 05:49 PM
Last Post: ndc85430
  AttributeError: 'area' object has no attribute 'areaofcircle' shane1236 5 396 Aug-02-2019, 06:44 AM
Last Post: shane1236
  Object attribute Uchikago 9 717 Jul-07-2019, 10:21 AM
Last Post: Gribouillis
  AttributeError: 'NoneType' object has no attribute 'get' ahmeddedo 1 2,478 May-27-2019, 05:57 AM
Last Post: heiner55
  AttributeError: 'tuple' object has no attribute 'interface' Kim6071 1 875 May-26-2019, 07:54 AM
Last Post: heiner55
  Error 'object has no attribute' when iterating thru a dictionary mrapple2020 8 976 Apr-08-2019, 01:36 AM
Last Post: mrapple2020
  AttributeError: 'ec2.ServiceResource' object has no attribute 'describe_instances' bluethundr 1 1,429 Feb-27-2019, 08:10 PM
Last Post: bluethundr
  'function' object has no attribute 'write' paramiko lateublegende 1 976 Feb-12-2019, 09:03 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)