def __setitem__( self, key, value ):

    if isinstance( value, bytearray ) or isinstance( value, str ):

      start_addr = 0
      stop_addr  = 0

      if isinstance( key, slice ):
        start_addr = int(key.start)
        stop_addr  = int(key.stop)
      else:
        start_addr = int(key)
        stop_addr  = int(key)+1

      self.mem[start_addr:stop_addr] = value

    else:

      start_addr = 0
      num_bytes  = 0

      if isinstance( key, slice ):
        start_addr = int(key.start)
        num_bytes  = int(key.stop) - int(key.start)
      else:
        start_addr = int(key)
        num_bytes  = 1

      if isinstance( value, Bits ):
        bits = value
        assert value.nbits % 8 == 0
      else:
        bits = Bits( num_bytes*8, value )

      for i in range(num_bytes):
        self.mem[start_addr+i] = bits[i*8:i*8+8]

  #-----------------------------------------------------------------------
  # getitem
  #-----------------------------------------------------------------------
dataset/ETHPy150Open cornell-brg/pymtl/pclib/fl/Bytes.py/Bytes.__setitem__/original