#!/usr/bin/env python
# -*- coding: utf-8 -*-
#python基礎教程最終的太陽黑子程式
from urllib import urlopen
from reportlab.graphics.shapes import *
from reportlab.graphics.charts.lineplots import lineplot
from reportlab.graphics.charts.textlabels import label
from reportlab.graphics import renderpdf
url = ''
comment_chars = '#:'
drawing = drawing(400, 200)
data =
for line in urlopen(url).readlines():
if not line.isspace() and not line[0] in comment_chars:
"""isspace()方法檢測字串是否只由空格組成, 語法 str.isspace(),如果字串只包含空格則返回true 否則返回false
python3
for line in request.urlopen(url).readlines():
if not line.decode('utf-8').isspace() and not line.decode('utf-8')[0] in comment_chars:
"""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]
#print(times)
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)]
#py3 加入list(zip(times, pred))否則報錯typeerror: 'zip' object is not subscriptable zip物件不可下標
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 items23.py',
fontsize=14, fillcolor=colors.red))
renderpdf.drawtofile(drawing, '/home/buntu/py5/items23.pdf', '2 title sunspots')
python基礎教程
乙個簡單的客戶機 import socket s socket.socket host socket.gethostname port 1234 s.bind host,port s.listen 5 while true c,addr s.accept print got connection f...
Python基礎教程
本教程不包括python的安裝,ide採用spyder pytho2.7 1.print pow 2,3 8 print 2 3 8這裡pow函式表示乘方,與 功能相同。2.abs 10 10abs函式用來求乙個數的絕對值。3.round 0.6 1.0 round 0.4 0.0round函式將浮...
Python 基礎教程
python由guido van rossum於1989年底發明,第乙個公開發行版發行於1991年。像perl語言一樣,python 源 同樣遵循 gpl gnu general public license 協議。本教程主要針對python 2.x版本的學習,如果你使用的是python 3.x版本...