This article is mainly for you to introduce the Basic Python Tutorial Project Two, a good picture, with a certain reference value, interested in small partners can refer to
This is the second item in the basic Python tutorial, about Python operations pdf.
The knowledge points involved
1, the use of urllib
2, the use of Reportlab library
This is a very simple example, but I found that in Python you can write a for loop directly in the array [], which is more convenient.
Here's the code:
From urllib import urlopenfrom reportlab.graphics.shapes import *from reportlab.graphics.charts.lineplots Import Lineplotfrom reportlab.graphics.charts.textlabels Import labelfrom reportlab.graphics Import renderpdfurl = '/http/ Www.swpc.noaa.gov/ftpdir/weekly/Predict.txt ' Comment_chars = ' #: ' drawing = drawing (+) data = []for line in Urlopen ( URL). ReadLines (): If not line.isspace () and not line[0] in COMMENT_CHARS:data.append ([Float (n) for N in Line.split ()]) PR ed = [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 fo R row in DATA]LP = LinePlot () lp.x = 50LP.Y = 50lp.height = 125lp.width = 300lp.data = [Zip (times, pred), Zip (times,high), Zi P (Times, low)]lp.lines[0].strokecolor = Colors.bluelp.lines[1].strokecolor = Colors.redlp.lines[2].strokecolor = COLORS.GREENDRAWING.ADD (LP) Drawing.add (String (250,150, ' sunspots ', fontsize=14,fillcolor=colors.red)) Renderpdf.drawtofile (drawing, ' report3.pdf ', ' sunspots ')