class_docstr: A space representing a string comprised of characters from a given charset.
  
  Example::
      >>> # {"", "B5", "hello", ...}
      >>> Text(5)
      >>> # {"0", "42", "0123456789", ...}
      >>> import string
      >>> Text(min_length = 1,
      ...      max_length = 10,
      ...      charset = string.digits)
class_docstr_tok: ["A","space","representing","a","string","comprised","of","characters","from","a","given","charset",".","Example",":",":",">",">",">","#","{","``","''",",","``","B5","''",",","``","hello","''",",","...","}",">",">",">","Text","(","5",")",">",">",">","#","{","``","0","''",",","``","42","''",",","``","0123456789","''",",","...","}",">",">",">","import","string",">",">",">","Text","(","min_length","=","1",",","...","max_length","=","10",",","...","charset","=","string.digits",")"]
docstr: Constructor of :class:`Text` space.
  
  Both bounds for text length are inclusive.
  
  Args:
      min_length (int): Minimum text length (in characters). Defaults to 1 to prevent empty strings.
      max_length (int): Maximum text length (in characters).
      charset (Union[set], str): Character set, defaults to the lower and upper english alphabet plus latin digits.
      seed: The seed for sampling from the space.
docstr_tok: ["Constructor","of",":","class",":","`","Text","`","space",".","Both","bounds","for","text","length","are","inclusive",".","Args",":","min_length","(","int",")",":","Minimum","text","length","(","in","characters",")",".","Defaults","to","1","to","prevent","empty","strings",".","max_length","(","int",")",":","Maximum","text","length","(","in","characters",")",".","charset","(","Union","[","set","]",",","str",")",":","Character","set",",","defaults","to","the","lower","and","upper","english","alphabet","plus","latin","digits",".","seed",":","The","seed","for","sampling","from","the","space","."]
code: def __init__(
      self,
      max_length: int,
      *,
      min_length: int = 1,
      charset: Union[Set[str], str] = alphanumeric,
      seed: Optional[Union[int, np.random.Generator]] = None,
  ):
      r"""Constructor of :class:`Text` space.
  
      Both bounds for text length are inclusive.
  
      Args:
          min_length (int): Minimum text length (in characters). Defaults to 1 to prevent empty strings.
          max_length (int): Maximum text length (in characters).
          charset (Union[set], str): Character set, defaults to the lower and upper english alphabet plus latin digits.
          seed: The seed for sampling from the space.
      """
      assert np.issubdtype(
          type(min_length), np.integer
      ), f"Expects the min_length to be an integer, actual type: {type(min_length)}"
      assert np.issubdtype(
          type(max_length), np.integer
      ), f"Expects the max_length to be an integer, actual type: {type(max_length)}"
      assert (
          0 <= min_length
      ), f"Minimum text length must be non-negative, actual value: {min_length}"
      assert (
          min_length <= max_length
      ), f"The min_length must be less than or equal to the max_length, min_length: {min_length}, max_length: {max_length}"
  
      self.min_length: int = int(min_length)
      self.max_length: int = int(max_length)
  
      self._char_set: FrozenSet[str] = frozenset(charset)
      self._char_list: Tuple[str, ...] = tuple(charset)
      self._char_index: Dict[str, np.int32] = {
          val: np.int32(i) for i, val in enumerate(tuple(charset))
      }
      self._char_str: str = "".join(sorted(tuple(charset)))
  
      # As the shape is dynamic (between min_length and max_length) then None
      super().__init__(dtype=str, seed=seed)
  
file_path: gym/gym/spaces/text.py
imports: from typing import Any, Dict, FrozenSet, Optional, Set, Tuple, Union
  import numpy
  from gym.spaces.space import Space
label_desc: Use image node_id 1 to create a new Text object from inherited base classes: Space with example: obj = Text(max_length)