verilog like class w/ bitslicing & int/long classtype

Stef Mientki stef.mientki at
Fri Jan 30 00:25:03 CET 2009

mark.seagoe at wrote:
> Thanks.  So far these solutions will return strings.  So I can't
> really treat it like a variable, yet still perform bitslice on it,
> since I need a special class to do bitslice and bit selection, but as
> soon as I try to pass it into some other function to check a bit, I
> gotta then do another operation to convert back to a variable.
> So I can get it to a point where I can do shadow_register[3] and get
> the value of any bit, or I can do shadow_register[4:2] and get a
> bitslice, and I can write them just as easily at this point.  If I add
> the __new__ method into the class, the instance obj becomes int, but
> is no longer slicable.  I think it looks like I can't have it both
> ways.
> --
try this:

class MyRegClass ( int ) :
  def __init__ ( self, value ) :
    self.Value = value
  def __repr__ ( self ) :
    line = hex ( self.Value )
    line = line [:2] + line [2:].upper()
    return line
  __str__ = __repr__


More information about the Python-list mailing list