Python module learns the test data of string

Source: Internet
Author: User

Some random data is needed during the test, and a string module in Python is used to record

#!/usr/bin/python#Coding:utf-8"""@author: bingo.he @file: data_factory.py @time: 2017/12/21"""ImportSocketImportstructImportstringImportRandomdefRandom_phoneno ():"""get random numbers"""    return '1'+"'. Join (Random.choice (string.digits) forIinchRange (10))defrandom_upper_code (length):"""get the random code of uppercase and digital"""    return "'. Join (Random.choice (string.ascii_uppercase + string.digits) forIinchrange (length))defrandom_lower_code (length):"""get a random code for lowercase letters and numbers"""    return "'. Join (Random.choice (string.ascii_lowercase + string.digits) forIinchrange (length))defrandom_ip ():"""get random IP"""Random_ip_pool= ['202.69.19.222/0'] Str_ip= Random_ip_pool[random.randint (0, Len (random_ip_pool)-1)] Str_ip_addr= Str_ip.split ('/') [0] Str_ip_mask= Str_ip.split ('/') [1] Ip_addr= Struct.unpack ('>i', Socket.inet_aton (STR_IP_ADDR)) [0] Mask= 0x0 forIinchRange (31-int, str_ip_mask), 1): Mask= Mask | (1 <<i) ip_addr_min= Ip_addr & (Mask & 0xFFFFFFFF) Ip_addr_max= Ip_addr | (~mask & 0xFFFFFFFF)    returnSocket.inet_ntoa (Struct.pack ('>i', Random.randint (Ip_addr_min, Ip_addr_max)))

PS: Bo Main company Use the mobile phone number check rule is 1, 11 digits can pass the calibration

Python module learns the test data of string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.