# Python 函数封装

1.北京时间转换为世界时

def BTC_to_UTC(btc_time):
utc_struct = time.mktime([int(btc_time[0:4]),int(btc_time[4:6]),\
int(btc_time[6:8]),int(btc_time[8:10]),\
int(btc_time[10:12]),int(btc_time[12:14]),0,0,0])

return time.strftime('%Y%m%d%H%M%S',time.gmtime(utc_struct)) + '%03s' %(btc_time[14:])

2.按照日期生成以一分钟为间隔的序列

strTimeBegin = datetime.datetime.strptime(dataListFirst,'%Y-%m-%d')
strTimeEnd = strTimeBegin + datetime.timedelta(days = 1)
strTimeMi = datetime.timedelta(minutes = 1)

while strTimeBegin < strTimeEnd:
dataListItem = [strTimeBegin.strftime('%Y-%m-%d'), strTimeBegin.strftime('%H:%M:%S.%f')[0:-3]]
returnDataList.append(dataListItem)
strTimeBegin = strTimeBegin + strTimeMi

3.平均值计算

for i in range(lenreDataList):
if i < len(returnDataList) - 1:
timeBegin = returnDataList[i][1]
timeEnd = returnDataList[i + 1][1]
else:
timeBegin = returnDataList[i][1]
timeEnd = '23:59:59:999'

dataListTemp = []
for j in range(lenDataList):
if dataList[j][1] > timeBegin and dataList[j][1] < timeEnd:
dataListTemp.append(dataList[j])

for e in avgList:
iCount = 0.0
for k in range(len(dataListTemp)):
if dataListTemp[k][e] != self.errorValue:
iCount += 1.0
if iCount != 0.0:
avgValue = '%.2e' %(addValue / iCount)
else:
avgValue = -999.9
returnDataList[i].append(avgValue)
return returnDataList          

#### python封装 （pyinstaller）

2018-03-19 18:16:46

#### python数据库函数的封装调用

2015-02-05 21:46:10

#### Python一些功能函数的封装

2018-03-14 23:53:23

#### Python----类的封装

2017-11-29 09:19:05

#### 如何将python程序封装成exe可执行文件

2016-02-25 00:48:53

#### python——类——封装 继承 多态

2017-04-28 10:08:02

#### python封装和解构

2018-04-01 21:48:36

#### 将python文件打包成exe可运行文件

2017-12-24 18:16:19

#### Python入门：面向对象编程-封装

2016-05-22 18:53:04

#### python笔记----解构和封装

2017-09-04 14:24:51