首页 > 学院 > 开发设计 > 正文

利用ForgeryPy生成虚拟数据

2019-11-11 05:04:39
字体:
来源:转载
供稿:网友

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

0x01 安装

采用pip进行安装:

pip install ForgeryPy

0x02 模块

打开源码

# -*- coding: utf-8 -*-# Copyright (C) 2012 by Tomasz Wójcik <labs@tomekwojcik.pl>## Permission is hereby granted, free of charge, to any person obtaining a copy# of this software and associated documentation files (the "Software"), to deal# in the Software without restriction, including without limitation the rights# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell# copies of the Software, and to permit persons to whom the Software is# furnished to do so, subject to the following conditions:## The above copyright notice and this permission notice shall be included in# all copies or substantial portions of the Software.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN# THE SOFTWARE."""Easy to use generator of various forged data."""from .forgery import addressfrom .forgery import basicfrom .forgery import currencyfrom .forgery import datefrom .forgery import internetfrom .forgery import lorem_ipsumfrom .forgery import namefrom .forgery import personal

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

0x03 例子

#coding:utf-8#导入模块import forgery_py#地理信息(城市)city=forgery_py.address.city()print city#随机颜色color=forgery_py.basic.hex_color()print color#时间data=forgery_py.date.date(True)print data#电子邮箱email=forgery_py.internet.email_address()print email#姓名name=forgery_py.name.full_name()print name#公司company=forgery_py.name.company_name()print company#简介about=forgery_py.lorem_ipsum.sentence()print about

其中一次的运行结果:

Paso Robles28E75D2017-01-18sandra@oloo.orgWayne KingZoomloungeMaecenas leo odio, condimentum id, luctus nec, molestie sed, justo.
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表