python构造数据1_column.py

Posted kane_zch

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python构造数据1_column.py相关的知识,希望对你有一定的参考价值。

#coding=utf-8
import random
import time
import datetime

TIMESTART = ‘2016-06-04 10:00:01‘

#increase time, string to time, then add seconds you want, at last, time to string
def increaseTime(base_time):
date_time = datetime.datetime.strptime(base_time,‘%Y-%m-%d %H:%M:%S‘) #string to datetime
time_time = time.mktime(date_time.timetuple()) #datetime to timestamp datetime.datetime(2016, 6, 4, 10, 0, 1)
time_time = time_time + 1 #1465005606.0
new_time = time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(time_time)) #‘2016-06-04 10:00:06‘
return new_time


def createTimeSet():
time = TIMESTART;
f=open(‘column.txt‘,‘w‘)
for i in range(1,101):
f.write(str(time) + ‘\n‘)
if i%3 == 0:
print i
time=increaseTime(time)
f.close()

 

macstart = 1;

def increaseMac(macparam):
return (macparam + 1)

def createMacSet():
mac = macstart
f=open(‘mac.txt‘,‘w‘)
for i in range(1,101):
macstr = ‘%012X‘ % mac
macstr = macstr[0]+macstr[1]+‘:‘+ macstr[2]+macstr[3]+‘:‘+macstr[4]+macstr[5]+‘:‘+macstr[6]+macstr[7]+‘:‘+macstr[8]+macstr[9]+‘:‘+macstr[10]+macstr[11]
f.write(macstr + ‘\n‘)
mac=mac+1
if i%3 == 0:
mac=macstart
f.close()

 

arrX=[]
arrY=[]

def initArrX(length):
for i in range(length):
X = random.randint(0, 1000)
arrX.append(X)
print arrX

def initArrY(length):
for i in range(length):
Y = random.randint(0, 640)
arrY.append(Y)
print arrY


def createXYSet():
initArrX(3)
initArrY(3)
f=open(‘xy.txt‘,‘w‘)
for i in range(0,100):
f.write(str(arrX[i%3]) +‘\n‘)
arrX[i%3] = arrX[i%3] + random.randint(-1, 1)
f.close()

 

# for i in range(0,100):
# f.write(str(arr[i%3]) +‘\n‘)
# arr[i%3] = arr[i%3] + random.randint(-1, 1)

以上是关于python构造数据1_column.py的主要内容,如果未能解决你的问题,请参考以下文章

测试数据不会造?可以用这个工具

Python--小笔记

接口测试

Python造数据模板

python encrypted_column.py

python基础:面向对象