利用ForgeryPy生成虚拟数据
2018-07-12 07:43:10来源:博客园 阅读 ()
在程序研发过程中,我们往往需要大量的虚拟实验数据。Python中有多个包可以用于生成虚拟数据,其中功能较为完善的是ForgeryPy。
1 安装
采用pip进行安装:
pip install ForgeryPy
2 模块
打开源码:
# -*- 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 address from .forgery import basic from .forgery import currency from .forgery import date from .forgery import internet from .forgery import lorem_ipsum from .forgery import name from .forgery import personal
ForgeryPy包括了地理位置、日期、网络、名称等大量虚拟生成算法,非常方便我们用来生成虚拟数据。
3 例子
#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 Robles 28E75D 2017-01-18 sandra@oloo.org Wayne King Zoomlounge Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo.
转自:https://blog.csdn.net/kikaylee/article/details/54906251
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- Python学习日记(十) 生成器和迭代器 2019-08-13
- 利用python自动生成verilog模块例化模板 2019-08-13
- 原创:Python编写通讯录,支持模糊查询,利用数据库存储 2019-07-24
- python学习-39 生成器总结 2019-07-24
- 单例模式 2019-07-24
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash