Locale la

faker.providers.lorem

class faker.providers.lorem.la.Provider(generator: Any)

Bases: Provider

Implement lorem provider for la locale.

get_words_list(part_of_speech: str | None = None, ext_word_list: Sequence[str] | None = None) List[str]

获取单词列表。

ext_word_list 参数允许用户提供一个单词列表来代替内置的单词列表。如果提供了 ext_word_list,则忽略 part_of_speech 的值。

part_of_speech 参数定义了返回的单词所属的词性。如果 ext_word_list 不是 None,则忽略 part_of_speech。如果 part_of_speech 的值与当前区域设置中存在的词性不对应,则会引发异常。

Sample:

part_of_speech=”abc”, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

Sample:

part_of_speech=”abc”

Sample:

ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

警告

根据区域提供者内置单词列表的长度或提供的 ext_word_list 的长度,如果 uniqueTrue,较大的 nb 可能会耗尽这些列表,从而引发异常。

paragraph(nb_sentences: int = 3, variable_nb_sentences: bool = True, ext_word_list: Sequence[str] | None = None) str

生成一个段落。

The nb_sentences argument controls how many sentences the paragraph will contain, and setting variable_nb_sentences to False will generate the exact amount, while setting it to True (default) will generate a random amount (+/-40%, minimum of 1) using randomize_nb_elements().

Under the hood, sentences() is used to generate the sentences, so the argument ext_word_list works in the same way here as it would in that method.

Sample:

nb_sentences=5

Sample:

nb_sentences=5, variable_nb_sentences=False

Sample:

nb_sentences=5, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

Sample:

nb_sentences=5, variable_nb_sentences=False, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

paragraphs(nb: int = 3, ext_word_list: Sequence[str] | None = None) List[str]

生成一个段落列表。

This method uses paragraph() under the hood to generate paragraphs, and the nb argument controls exactly how many sentences the list will contain. The ext_word_list argument works in exactly the same way as well.

Sample:

nb=5

Sample:

nb=5, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

sentence(nb_words: int = 6, variable_nb_words: bool = True, ext_word_list: Sequence[str] | None = None) str

生成一个句子。

The nb_words argument controls how many words the sentence will contain, and setting variable_nb_words to False will generate the exact amount, while setting it to True (default) will generate a random amount (+/-40%, minimum of 1) using randomize_nb_elements().

Under the hood, words() is used to generate the words, so the argument ext_word_list works in the same way here as it would in that method.

Sample:

nb_words=10

Sample:

nb_words=10, variable_nb_words=False

Sample:

nb_words=10, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

Sample:

nb_words=10, variable_nb_words=True, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

sentences(nb: int = 3, ext_word_list: Sequence[str] | None = None) List[str]

生成一个句子列表。

This method uses sentence() under the hood to generate sentences, and the nb argument controls exactly how many sentences the list will contain. The ext_word_list argument works in exactly the same way as well.

Sample:

Sample:

nb=5

Sample:

nb=5, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

text(max_nb_chars: int = 200, ext_word_list: Sequence[str] | None = None) str

生成一个文本字符串。

The max_nb_chars argument controls the approximate number of characters the text string will have, and depending on its value, this method may use either words(), sentences(), or paragraphs() for text generation. The ext_word_list argument works in exactly the same way it would in any of those methods.

Sample:

max_nb_chars=20

Sample:

max_nb_chars=80

Sample:

max_nb_chars=160

Sample:

ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

texts(nb_texts: int = 3, max_nb_chars: int = 200, ext_word_list: Sequence[str] | None = None) List[str]

生成一个文本字符串列表。

The nb_texts argument controls how many text strings the list will contain, and this method uses text() under the hood for text generation, so the two remaining arguments, max_nb_chars and ext_word_list will work in exactly the same way as well.

Sample:

nb_texts=5

Sample:

nb_texts=5, max_nb_chars=50

Sample:

nb_texts=5, max_nb_chars=50, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

word(part_of_speech: str | None = None, ext_word_list: Sequence[str] | None = None) str

生成一个单词。

This method uses words() under the hood with the nb argument set to 1 to generate the result.

Sample:

Sample:

ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

words(nb: int = 3, ext_word_list: List[str] | None = None, part_of_speech: str | None = None, unique: bool = False) List[str]

生成一个单词元组。

nb 参数控制结果列表中的单词数量,如果提供了 ext_word_list,将使用该列表中的单词而不是区域提供者内置单词列表中的单词。

如果未提供 word_list,该方法将使用默认值 None,这将导致该方法调用 get_words_list 方法来获取单词列表。如果提供了 word_list,该方法将使用提供的列表。

If unique is True, this method will return a list containing unique words. Under the hood, random_sample() will be used for sampling without replacement. If unique is False, random_choices() is used instead, and the list returned may contain duplicates.

Sample:

Sample:

nb=5

Sample:

nb=5, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’]

Sample:

nb=4, ext_word_list=[‘abc’, ‘def’, ‘ghi’, ‘jkl’], unique=True