• 利用ForgeryPy生成虚拟数据


      在程序研发过程中,我们往往需要大量的虚拟实验数据。Python中有多个包可以用于生成虚拟数据,其中功能较为完善的是ForgeryPy。

    源码:

     1 # -*- coding: utf-8 -*-
     2 # Copyright (C) 2012 by Tomasz Wójcik <labs@tomekwojcik.pl>
     3 #
     4 # Permission is hereby granted, free of charge, to any person obtaining a copy
     5 # of this software and associated documentation files (the "Software"), to deal
     6 # in the Software without restriction, including without limitation the rights
     7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8 # copies of the Software, and to permit persons to whom the Software is
     9 # furnished to do so, subject to the following conditions:
    10 #
    11 # The above copyright notice and this permission notice shall be included in
    12 # all copies or substantial portions of the Software.
    13 #
    14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    20 # THE SOFTWARE.
    21 
    22 """Easy to use generator of various forged data."""
    23 
    24 from .forgery import address
    25 from .forgery import basic
    26 from .forgery import currency
    27 from .forgery import date
    28 from .forgery import internet
    29 from .forgery import lorem_ipsum
    30 from .forgery import name
    31 from .forgery import personal

    ForgeryPy包括了地理位置、日期、网络、名称等大量虚拟生成算法,非常方便我们用来生成虚拟数据。

    案例:

     1 #coding:utf-8
     2 
     3 #导入模块
     4 import forgery_py
     5 
     6 #地理信息(城市)
     7 city=forgery_py.address.city()
     8 print city
     9 #随机颜色
    10 color=forgery_py.basic.hex_color()
    11 print color
    12 #时间
    13 data=forgery_py.date.date(True)
    14 print data
    15 #电子邮箱
    16 email=forgery_py.internet.email_address()
    17 print email
    18 #姓名
    19 name=forgery_py.name.full_name()
    20 print name
    21 #公司
    22 company=forgery_py.name.company_name()
    23 print company
    24 #简介
    25 about=forgery_py.lorem_ipsum.sentence()
    26 print about

    学习地址:

                 http://blog.csdn.net/kikaylee/article/details/54906251

  • 相关阅读:
    DOM-window下的常用子对象-location-刷新页面
    row_number over( partition by xx)
    linux openjdk安装
    ffmpeg直播系统
    flink 基本原理
    flink分层 api
    flink测试用例编写
    使用mybatis的动态sql解析能力生成sql
    大数据量显示问题
    vue使用日记
  • 原文地址:https://www.cnblogs.com/python-nameless/p/7866180.html
Copyright © 2020-2023  润新知