Greetings.
I need a little help understanding Scope of methods in a class. I am getting an "object not defined" error and I cannot figure out why (I don't program using classes often).
If this class is within the main program, it runs fine. I moved it to an external library and import it into the main program and it doesn't run with the object not defined error related to "unpack_from".
Being that "calcsize" works (but is used within "___init___", and "calcsize" does not work but is within a method, I suspect this is a problem related to scope. I have tried everything I could think of and everything I could find on Google search but can't get passed this problem.
Thanks in advance for helping me get back on track!
Chris
I need a little help understanding Scope of methods in a class. I am getting an "object not defined" error and I cannot figure out why (I don't program using classes often).
If this class is within the main program, it runs fine. I moved it to an external library and import it into the main program and it doesn't run with the object not defined error related to "unpack_from".
Being that "calcsize" works (but is used within "___init___", and "calcsize" does not work but is within a method, I suspect this is a problem related to scope. I have tried everything I could think of and everything I could find on Google search but can't get passed this problem.
Thanks in advance for helping me get back on track!
Chris
Code:
class Sensors: def __init__(self): from machine import Pin, ADC, I2C # Need these interface / IO [from struct import calcsize from struct import unpack_from .... define attributes setup hardware (pins) Configure i2C inerfaces ...... self.TCRMESSAGE_OFFSET = self.TCR_LENGTH_OFFSET + calcsize(self.TCR_LENGTH_FORMAT) #NOTE! CALCSIZE works find here .... MORE CODE .... def Check_Code(self): self.QR_Detect_Flag = 0 read_data = self.i2c.readfrom(self.TCR_I2C_ADDRESS, self.TCR_I2C_BYTE_COUNT) message_length, = self.[b]unpack_from[/b](self.TCR_LENGTH_FORMAT, read_data, self.TCR_LENGTH_OFFSET) # NOTE! UNPACK_FROM causes Object not defined. ... MORE CODE ....
Statistics: Posted by Chris D — Mon Nov 18, 2024 9:13 am