Locale la¶
faker.providers.lorem¶
- class faker.providers.lorem.la.Provider(generator: Any)¶
Bases:
ProviderImplement lorem provider for
lalocale.- 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的长度,如果unique为True,较大的nb可能会耗尽这些列表,从而引发异常。
- paragraph(nb_sentences: int = 3, variable_nb_sentences: bool = True, ext_word_list: Sequence[str] | None = None) str¶
生成一个段落。
The
nb_sentencesargument controls how many sentences the paragraph will contain, and settingvariable_nb_sentencestoFalsewill generate the exact amount, while setting it toTrue(default) will generate a random amount (+/-40%, minimum of 1) usingrandomize_nb_elements().Under the hood,
sentences()is used to generate the sentences, so the argumentext_word_listworks 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 thenbargument controls exactly how many sentences the list will contain. Theext_word_listargument 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_wordsargument controls how many words the sentence will contain, and settingvariable_nb_wordstoFalsewill generate the exact amount, while setting it toTrue(default) will generate a random amount (+/-40%, minimum of 1) usingrandomize_nb_elements().Under the hood,
words()is used to generate the words, so the argumentext_word_listworks 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 thenbargument controls exactly how many sentences the list will contain. Theext_word_listargument 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_charsargument controls the approximate number of characters the text string will have, and depending on its value, this method may use eitherwords(),sentences(), orparagraphs()for text generation. Theext_word_listargument 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_textsargument controls how many text strings the list will contain, and this method usestext()under the hood for text generation, so the two remaining arguments,max_nb_charsandext_word_listwill 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 thenbargument set to1to 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
uniqueisTrue, this method will return a list containing unique words. Under the hood,random_sample()will be used for sampling without replacement. IfuniqueisFalse,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