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
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
pip install faker Copy code
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
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
fake.license_plate() # License plate # 'ZCO 000' Copy code
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
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
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
author[Hz in nuggets 75963],Please bring the original link to reprint, thank you.
The sidebar is recommended
- [recalling the 1970s] using Python to repair the wonderful memories of parents' generation, black-and-white photos become color photos
- You used to know Python advanced
- Pyinstaller package Python project
- 2021 IEEE programming language rankings: Python tops the list!
- Implementation of Python automatic test control
- Python advanced: [Baidu translation reverse] graphic and video teaching!!!
- Do you know the fuzzy semantics in Python syntax?
- [Python from introduction to mastery] (XXVII) learn more about pilot!
- Playing excel office automation with Python
- Some applications of heapq module of Python module
guess what you like
Python and go languages are so popular, which is more suitable for you?
Python practical skills task segmentation
Python simulated Login, numpy module, python simulated epidemic spread
Python opencv contour discovery function based on image edge extraction
Application of Hoff circle detection in Python opencv
Python reptile test ox knife (I)
Day 1: learn the Django framework of Python development
django -- minio_ S3 file storage service
[algorithm learning] 02.03 Delete intermediate nodes (Java / C / C + + / Python / go)
Similarities and differences of five pandas combinatorial functions
- Learning in Python + opencv -- extracting corners
- Python beginner's eighth day ()
- Necessary knowledge of Python: take you to learn regular expressions from zero
- Get your girlfriend's chat records with Python and solve the paranoia with one move
- My new book "Python 3 web crawler development practice (Second Edition)" has been recommended by the father of Python!
- From zero to familiarity, it will take you to master the use of Python len() function
- Python type hint type annotation guide
- leetcode 108. Convert Sorted Array to Binary Search Tree（python）
- For the geometric transformation of Python OpenCV image, let's first talk about the extraordinary resize function
- leetcode 701. Insert into a Binary Search Tree （python）
- For another 3 days, I sorted out 80 Python datetime examples, which must be collected!
- Python crawler actual combat | using multithreading to crawl lol HD Wallpaper
- Complete a python game in 28 minutes, "customer service play over the president card"
- The universal Python praise machine (commonly known as the brushing machine) in the whole network. Do you want to know the principle? After reading this article, you can write one yourself
- How does Python compare file differences between two paths
- Common OS operations for Python
- [Python data structure series] linear table - explanation of knowledge points + code implementation
- How Python parses web pages using BS4
- How do Python Network requests pass parameters
- Python core programming - decorator
- Python Network Programming -- create a simple UPD socket to realize mutual communication between two processes
- leetcode 110. Balanced Binary Tree（python）
- Django uses Django celery beat to dynamically add scheduled tasks
- The bear child said "you haven't seen Altman" and hurriedly studied it in Python. Unexpectedly
- Optimization iteration of nearest neighbor interpolation and bilinear interpolation algorithm for Python OpenCV image
- Bilinear interpolation algorithm for Python OpenCV image, the most detailed algorithm description in the whole network
- Use of Python partial()
- Python game development, pyGame module, python implementation of angry birds
- leetcode 1104. Path In Zigzag Labelled Binary Tree（python）
- Save time and effort. 10 lines of Python code automatically clean up duplicate files in the computer
- Learn python, know more meat, and be a "meat expert" in the technical circle. One article is enough
- [Python data structure series] "stack (sequential stack and chain stack)" -- Explanation of knowledge points + code implementation
- Datetime module of Python time series
- Python encrypts and decrypts des to solve the problem of inconsistency with Java results
- Chapter 1: introduction to Python programming-4 Hello World
- Summary of Python technical points
- 11.5K Star！ An open source Python static type checking Library
- Chapter 2: Fundamentals of python-1 grammar
- [Python daily homework] day4: write a function to count the number of occurrences of each number in the incoming list and return the corresponding dictionary.
- Python uses turtle to express white