此博客以后永不更新阴险阴险阴险阴险阴险阴险 国内唯一更新博客在此处不在更新,谢谢,请看下面的地址和邮箱! 我的博客园:http://www.cnblogs.com/mhxy13867806343/ 欢迎访问! 邮箱:mhxy13867806343@sina.cn/ 国内更新博客在:https://github.com/mhxy13867806343 微信公众号:pyjs
分类: Python/Ruby
2015-09-15 18:18:00
#python操作PDF
from urllib import urlopen
from reportlab.graphics.shapes import *
from reportlab.graphics.charts.legends import *
from reportlab.graphics.charts.textlabels import *
from reportlab.graphics import renderPDF
url=''
COMMENT_CHAT='#'
drawing=Drawing(400,200)
data=[]
for line in urlopen(url).readlines():
if not line.isspace() and not line[0] in COMMENT_CHAT:
data.append([float(n) for n in line.split()])
pred=[row[2]for row in data]
high=[row[3]for row in data]
low=[row[4]for row in data]
times=[row[0]+row[1]/12.0 for row in data]
from reportlab.graphics.charts.lineplots import LinePlot
lp=LinePlot()
lp.x=50
lp.y=50
lp.height=125
lp.width=300
lp.data=[zip(times,pred),zip(times,high),zip(times,low)]
lp.lines[0].strokeColor=colors.blue
lp.lines[1].strokeColor=colors.red
lp.lines[2].strokeColor=colors.green
drawing.add(lp)
drawing.add(String(250,150,'Sunspots',fontSize=14,filllColr=colors.red))
renderPDF.drawToFile(drawing,'report3.pdf','Sunspots')
这是我的错误 ,那位朋友帮看下,如何解决下
File "G:/py_py/python_object_xyz/obj_python/python_pdf.py", line 16, in <module>
data.append([float(n) for n in line.split()])
ValueError: could not convert string to float: <!DOCTYPE