前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >利用ForgeryPy生成虚拟数据

利用ForgeryPy生成虚拟数据

作者头像
用户1214487
发布2018-07-31 17:31:28
4100
发布2018-07-31 17:31:28
举报
文章被收录于专栏:PythonPython

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

1 安装

采用pip进行安装:

代码语言:javascript
复制
pip install ForgeryPy

2 模块

打开源码:

代码语言:javascript
复制
# -*- 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 例子

代码语言:javascript
复制
#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

其中一次的运行结果:

代码语言:javascript
复制
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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-07-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 安装
  • 2 模块
  • 3 例子
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档