![]() |
Object cannot find its attribute - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Object cannot find its attribute (/thread-21428.html) |
Object cannot find its attribute - colt - Sep-29-2019 Hello, I have this line of code print ("Identifier Byte: {}".format(self.identity_byte))that generates this output: Quote:120 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 RE: Object cannot find its attribute - ichabod801 - Sep-30-2019 (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. RE: Object cannot find its attribute - colt - Oct-06-2019 (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. True. Nonetheless, the problem persists (same error message). RE: Object cannot find its attribute - ichabod801 - Oct-06-2019 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? RE: Object cannot find its attribute - buran - Oct-06-2019 Note that __metaclass_ on line 5 is missing one underscore RE: Object cannot find its attribute - colt - Oct-08-2019 (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: I tried with instruction = Instruction(b'X')and received: Quote: File "test.py", line 55 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. RE: Object cannot find its attribute - ichabod801 - Oct-09-2019 Well, if you can't come up with a smaller version of your code that shows the error, I can't help you.
|