In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces based on Python how to use Faker batch test data related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this article on how to use Faker batch test data based on Python, let's take a look.
In the process of testing, it is often necessary to create data in batches, and there are many methods, the most simple and convenient one should be to use Faker, a third-party library of python.
Script function, batch generate 10000 pieces of basic data, write to the local file: test_data.csv
Execute on the linux server, take the test_data.csv to the local windows,excel and open the possible Chinese garbled code. You can use: data-Import data from text / CSV, modify the encoding format, and display Chinese normally.
The following is a detailed script:
Import csvfrom faker import Fakerimport datetimefake = Faker (['zh_CN']) file = open ("test_data.csv", "w", newline= "")
Create a file, which is the file name, w opening method (w represents new, if it already exists, delete rewrite), newline (if not added, there will be one more blank line for each row of data)
Fwrite = csv.writer (file)
Get the object to write to the file:
Fwrite.writerow (["name", "phone", "Card_id", "Company", "address", "Credit Card", "position", "email"])
Write the title header:
For i in range (9999): user_name = fake.name () phone = fake.phone_number () card_id = fake.ssn () company = fake.company () addr = fake.address () bank_card = fake.credit_card_number () title = fake.job () email = fake.email () fwrite.writerow ([user_name, phone, card_id, company, addr, bank_card, title, email])
Write a row of data:
File.close ()
Effect Preview:
This is the end of the article on "how to use Faker batch Test data based on Python". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use Faker batch test data based on Python". If you want to learn more knowledge, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.