在程序研發過程當中,咱們每每須要大量的虛擬實驗數據。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包括了地理位置、日期、網絡、名稱等大量虛擬生成算法,很是方便咱們用來生成虛擬數據。學習
案例:this
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
學習地址:spa
http://blog.csdn.net/kikaylee/article/details/54906251.net