程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Pythonopen file, take out a column, convert it into days, and then compare it with the current time [the number of days from January 1 to the present] to get the unavailable percentage

編輯:Python
#!/usr/bin/python
import time,datetime
from datetime import date
file = '/Users/jian.wang13/code/test/0629shijian.txt'
list = []
with open(file,'r',encoding='utf-8') as f:
for i in f:
tmp = i.strip()
list.append(tmp)
current_data = datetime.datetime.now().strftime('%Y-%m-%d')
print(current_data)
a,b,c = map(int,current_data.split('-'))
print(a,b,c)
num = date(a,b,c)
yuan_dan = date(num.year+0,1,1)
#jisuan = yuan_dan - num
jisuan = num - yuan_dan
jisuan1 = str(jisuan)
jisuan1 = jisuan1.split(' ')
jisuan2 = jisuan1[0]
print(jisuan2)
print(list)
sum = 0
for i in list:
sum += float(i)
print((sum/float(jisuan2))*100)

Time file

5
1.8
2.5


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved