This is a snippet for registers for an emulator I'm working on:
class registers(object):
def __init__(self):
self._AF = registerpair()
def _get_AF(self):
return self._AF.getval()
def _set_AF(self, val):
self._AF.setval(val)
AF = property(_get_AF, _set_AF)
The registerpair()
class has an increment()
method. I would like to know if there is any way I could do the following:
r = registers()
r.AF.increment()
rather than having to do:
r._AF.increment()
As is, no. You have set the fget
method to return a getval()
for your registerpair()
class.
Since the property is for the _AF
attribute which is a registerpair()
instance, I believe it would be more reasonable to change your fget
(and fset
for that matter) to actually return it, and maybe create an auxiliary function to actually get the value with getval()
or access it directly.
So if your _get_AF
looked something like:
def _get_AF(self):
return self._AF
you can then call r.AF.increment()
just fine. Then you could move the getval()
call to another function in your class:
def getAFval(self):
self._AF.getval()
Or just make direct calls like r.AF.getval()
which seems like the most clear way to do things.