absfuyu.dxt.strext module

Absfuyu: Data Extension

str extension

Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)

class absfuyu.dxt.strext.Text[source]

Bases: ShowAllMethodsMixin, str

str extension

divide(string_split_size: int = 60) list[str][source]

Divide long string into smaller size

Parameters:

string_split_size (int) – Divide string every x character (Default: 60)

Returns:

A list in which each item is a smaller string with the size of string_split_size (need to be concaternate later)

Return type:

list[str]

Example:

>>> test = Text("This is an extremely long line of text!")
>>> test.divide(string_split_size=20)
['This is an extremely', ' long line of text!']
divide_with_variable(split_size: int = 60, split_var_len: int = 12, custom_var_name: str | None = None) list[str][source]

Divide long string into smaller size, then assign a random variable to splited string for later use

Parameters:
  • split_size (int) – Divide string every x character (Default: 60)

  • split_var_len (int) – Length of variable name assigned to each item (Default: 12)

  • custom_var_name (str) – Custom variable name when join string

Returns:

A list in which each item is a smaller string with the size of split_size and a way to concaternate them (when using print())

Return type:

list[str]

Example:

>>> test = Text("This is an extremely long line of text!")
>>> test.divide_with_variable(split_size=20)
[
    "qNTCnmkFPTJg='This is an extremely'",
    "vkmLBUykYYDG=' long line of text!'",
    'sBoSwEfoxBIH=qNTCnmkFPTJg+vkmLBUykYYDG',
    'sBoSwEfoxBIH'
]
>>> test = Text("This is an extremely long line of text!")
>>> test.divide_with_variable(split_size=20, custom_var_name="test")
[
    "test1='This is an extremely'",
    "test2=' long line of text!'",
    'test=test1+test2',
    'test'
]
analyze(full: bool = False) TextAnalyzeDictFormat[source]

String analyze (count number of type of character)

Parameters:

full (bool) – Full analyze when True (Default: False)

Returns:

A dictionary contains number of digit character, uppercase character, lowercase character, and special character

Return type:

dict | TextAnalyzeDictFormat

Example:

>>> test = Text("Random T3xt!")
>>> test.analyze()
{'digit': 1, 'uppercase': 2, 'lowercase': 7, 'other': 2}

Changed in version 3.3.0: Updated functionality

reverse() Self[source]

Reverse the string

Returns:

Reversed string

Return type:

Text

Example:

>>> test = Text("Hello, World!")
>>> test.reverse()
'!dlroW ,olleH'
is_pangram(custom_alphabet: set[str] | None = None) bool[source]

Check if string is a pangram

A pangram is a unique sentence in which every letter of the alphabet is used at least once

Parameters:

custom_alphabet (set[str] | None, optional) – Custom alphabet to use (Default: None)

Returns:

True if string is a pangram
False if string is not a pangram

Return type:

bool

Changed in version 5.0.0: Add ``custom_alphabet`` parameter

is_palindrome() bool[source]

Check if string is a palindrome

A palindrome is a word, verse, or sentence or a number that reads the same backward or forward

Returns:

True if string is a palindrome
False if string is not a palindrome

Return type:

bool

to_hex(raw: bool = False) str[source]

Convert string to hex form

Parameters:

raw (bool) –

False: hex string in the form of \x (default)
True: normal hex string

Returns:

Hexed string

Return type:

str

Example:

>>> test = Text("Hello, World!")
>>> test.to_hex()
'\\x48\\x65\\x6c\\x6c\\x6f\\x2c\\x20\\x57\\x6f\\x72\\x6c\\x64\\x21'
random_capslock(probability: int = 50) Self[source]

Randomly capslock letter in string

Parameters:

probability (int) – Probability in range [0, 100] (Default: 50)

Returns:

Random capslocked text

Return type:

Text

Example:

>>> test = Text("This is an extremely long line of text!")
>>> test.random_capslock()
'tHis iS An ExtREmELY loNg liNE oF tExT!'
reverse_capslock() Self[source]

Reverse capslock in string

Returns:

Reversed capslock Text

Return type:

Text

Example:

>>> test = Text("Foo")
>>> test.reverse_capslock()
'fOO'

Changed in version 5.0.0: Use ``str.swapcase()``

to_list() list[str][source]

Convert into list

Returns:

List of string

Return type:

list[str]

Example:

>>> test = Text("test")
>>> test.to_list()
['t', 'e', 's', 't']
to_listext() None[source]

Deprecated, will be removed soon

Deprecated in version 5.0.0: Unused

count_pattern(pattern: str, ignore_capslock: bool = False) int[source]

Returns how many times pattern appears in text

Parameters:
  • pattern (str) – Pattern to count

  • ignore_capslock (bool) – Ignore the pattern uppercase or lowercase (Default: False - Exact match)

Returns:

How many times pattern appeared

Return type:

int

Example:

>>> Text("test").count_pattern("t")
2

Added in version 3.3.0

hapax(strict: bool = False) list[str][source]

A hapax legomenon (often abbreviated to hapax) is a word which occurs only once in either the written record of a language, the works of an author, or in a single text.

This function returns a list of hapaxes (if any) (Lettercase is ignored)

Parameters:

strict (bool) – Remove all special characters before checking for hapax (Default: False)

Returns:

A list of hapaxes

Return type:

list[str]

Example:

>>> test = Text("A a. a, b c c= C| d d")
>>> test.hapax()
['a', 'a.', 'a,', 'b', 'c', 'c=', 'c|']
>>> test.hapax(strict=True)
['b']

Added in version 3.3.0

shorten(shorten_size: int = 60) str[source]

Shorten long text

Parameters:

shorten_size (int, optional) – How many characters per line. Minimum is 1, by default 60

Returns:

Shortened text

Return type:

str

Example:

>>> test = Text("a" * 200)
>>> test.shorten()
(
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaa'
)

Added in version 5.0.0

class absfuyu.dxt.strext.TextAnalyzeDictFormat[source]

Bases: TypedDict

Dict format for Text.analyze() method

Parameters:
  • digit (int) – Number of digit characters

  • uppercase (int) – Number of uppercase characters

  • lowercase (int) – Number of lowercase characters

  • other (int) – Number of other printable characters

  • is_pangram (NotRequired[bool]) – Is a pangram (Not required)

  • is_palindrome (NotRequired[bool]) – Is a palindrome (Not required)

digit: int
uppercase: int
lowercase: int
other: int
is_pangram: NotRequired[bool]
is_palindrome: NotRequired[bool]