Split a string var into a list. Args: other: The string to split the var with. Returns: A var with the list. Raises: TypeError: If the var is not a string.
(self, other: str | Var[str] = " ")
| 1272 | ) |
| 1273 | |
| 1274 | def split(self, other: str | Var[str] = " ") -> Var: |
| 1275 | """Split a string var into a list. |
| 1276 | |
| 1277 | Args: |
| 1278 | other: The string to split the var with. |
| 1279 | |
| 1280 | Returns: |
| 1281 | A var with the list. |
| 1282 | |
| 1283 | Raises: |
| 1284 | TypeError: If the var is not a string. |
| 1285 | """ |
| 1286 | if not types._issubclass(self._var_type, str): |
| 1287 | raise TypeError(f"Cannot split non-string var {self._var_full_name}.") |
| 1288 | |
| 1289 | other = Var.create_safe(json.dumps(other)) if isinstance(other, str) else other |
| 1290 | |
| 1291 | return self._replace( |
| 1292 | _var_name=f"{self._var_name}.split({other._var_full_name})", |
| 1293 | _var_is_string=False, |
| 1294 | _var_type=list[str], |
| 1295 | merge_var_data=other._var_data, |
| 1296 | ) |
| 1297 | |
| 1298 | def join(self, other: str | Var[str] | None = None) -> Var: |
| 1299 | """Join a list var into a string. |