current position:Home>Python: faker extension package

Python: faker extension package

2022-01-30 07:39:55 Hz in nuggets 75963

Refer to the website

https://zhuanlan.zhihu.com/p/87203290
 Copy code 

Preface

 In the process of programming , We often need to use a lot of data to ` test `.
 If ` Manual manufacturing data ` Words , It must take a lot of energy , It's not reasonable .
 At this point we should use Faker This Python library ( Expansion pack, ), Use it to generate all kinds of ` Pseudo data `.
 Copy code 

install

pip install faker
 Copy code 

Basic usage


from faker import Faker    #   from faker Module import Faker This class .
fake = Faker()       #   Instantiation , Save to variable fake in . 
 
fake.name()           #   call name() Method randomly generates a name . 
# Donna Kelly
 
fake.address()           #   call address() Method randomly generates address information .
# 519 Donna River


#  If you want to generate Chinese random data , We can give... When instantiating locale Parameters of the incoming ‘zh_CN’ This value :
from faker import Faker           
fake = Faker(locale='zh_CN')       
 
fake.name()                        
#  Pang Chao 
 
fake.address()                     
#  Hechuan Zhangjie, Xinji County, Hebei Province p seat  489476


#  If you want to generate traditional Chinese characters , It can be introduced into the value of Taiwan, China. 'zh_TW'( Of course, the address shows Taiwan ):
from faker import Faker           
fake = Faker(locale='zh_TW')       
 
fake.name()                        
#  Luo wanting 
 
fake.address()                     
# 16934  Shuiyuan lane, Dali County 35 Hao Zhi 0


#  If you want to generate data in other languages or regions , We can pass in the corresponding region value :
ar_EG - Arabic (Egypt)
ar_PS - Arabic (Palestine)
ar_SA - Arabic (Saudi Arabia)
bg_BG - Bulgarian
bs_BA - Bosnian
cs_CZ - Czech
de_DE - German
dk_DK - Danish
el_GR - Greek
en_AU - English (Australia)
en_CA - English (Canada)
en_GB - English (Great Britain)
en_NZ - English (New Zealand)
en_US - English (United States)
es_ES - Spanish (Spain)
es_MX - Spanish (Mexico)
et_EE - Estonian
fa_IR - Persian (Iran)
fi_FI - Finnish
fr_FR - French
hi_IN - Hindi
hr_HR - Croatian
hu_HU - Hungarian
hy_AM - Armenian
it_IT - Italian
ja_JP - Japanese
ka_GE - Georgian (Georgia)
ko_KR - Korean
lt_LT - Lithuanian
lv_LV - Latvian
ne_NP - Nepali
nl_NL - Dutch (Netherlands)
no_NO - Norwegian
pl_PL - Polish
pt_BR - Portuguese (Brazil)
pt_PT - Portuguese (Portugal)
ro_RO - Romanian
ru_RU - Russian
sl_SI - Slovene
sv_SE - Swedish
tr_TR - Turkish
uk_UA - Ukrainian
zh_CN - Chinese (China Mainland)
zh_TW - Chinese (China Taiwan)

 Copy code 

faker Other methods

 notes : Individual methods are targeted , such as province() The method is applicable to China , But it does not apply to the United States and some other countries .
 Copy code 

Address related

fake.address()            #  Address 
# ' Shang Jie Zhong Jie, Daye County, Hong Kong Special Administrative Region k seat  664713'
 
fake.building_number()    #  Building name  
# 'v seat '
 
fake.city()               #  Complete city name 
# ' Changchun County '
 
fake.city_name()          #  City name ( Without city and county )
# ' Wuzhou '
 
fake.city_suffix()        #  City suffix 
# ' City '
 
fake.country()            #  Country name 
# ' Eritrea '
 
fake.country_code(representation="alpha-2")
# 'BZ' #  Country number 
 
fake.district()           #  region 
# ' Shawan '

fake.postcode()           #  Zip code 
# '332991'
 
fake.province()           #  province 
# ' Hebei Province '
 
fake.street_address()     #  Street address 
# ' Wuhan Street D seat '
 
fake.street_name()        #  Street name 
# ' Guangzhou road '
 
fake.street_suffix()      #  Street suffix 
# ' road '

 Copy code 

Automobile related

fake.license_plate()      #  License plate 
# 'ZCO 000'
 Copy code 

Bank related

fake.bank_country()          #  Country of Bank 
# 'GB'
 
fake.bban()                  #  Basic bank account number 
# 'TPET9323218579379' 
 
fake.iban()                  #  International Bank Code 
# 'GB82IRVM1531009974701'
 Copy code 

Bar code related

fake.ean(length=13)    # EAN Bar code 
# '5456457843465'
 
fake.ean13()           # EAN13 Bar code 
# '2689789887590'
 
fake.ean8()            # EAN8 Bar code 
# '52227936'
 Copy code 

Color related

fake.color_name()        #  Color name 
# 'Orange'
 
fake.hex_color()         #  Color hexadecimal value 
# '#a5cb7c'
 
fake.rgb_color()         #  Color RGB value 
# '15,245,42'
 
fake.rgb_css_color()     # CSS Color value 
# 'rgb(15,70,13)'
 
fake.safe_color_name()   #  Safe color 
# 'aqua'
 
fake.safe_hex_color()    #  Security color hex value 
# '#881100'
 Copy code 

Company related

fake.bs()                 #  Business words 
# 'synthesize strategic vortals'
 
fake.catch_phrase()       #  Witticism ( slogan )
# 'Robust even-keeled service-desk'
 
fake.company()            #  Corporate name 
# ' Fuyu Technology Co., Ltd '
 
fake.company_prefix()     #  Company name prefix 
# ' Shangruan Guanlian '
 
fake.company_suffix()     #  Company name suffix 
# ' Network Co., Ltd '
 Copy code 

copyright notice
author[Hz in nuggets 75963],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201300739396206.html

Random recommended