<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def count_range(self, txn, from_key, to_key):
 """ Counter number of records in the perstistent map with keys within the given range. :param txn: The transaction in which to run. :type txn: :class:`zlmdb.Transaction` :param from_key: Count records starting and including from this key. :type from_key: object :param to_key: End counting records before this key. :type to_key: object :returns: The number of records. :rtype: int """

        key_from = struct.pack('>H', self._slot) + self._serialize_key(from_key)
        to_key = struct.pack('>H', self._slot) + self._serialize_key(to_key)

        cnt = 0
        cursor = txn._txn.cursor()
        has_more = cursor.set_range(key_from)
        while has_more:
            if cursor.key() >= to_key:
                break
            cnt += 1
            has_more = cursor.next()

        return cnt