范占伟(军旗) 2009年09月24日 星期四 10:10 | 1895次浏览 | 1条评论
from gasp import*有问题
如果你读过或者正在读<<HOW TO THINK LIKE A COMPUTER SCIENTIST>>这本书,你一定知道下面的一段话:
GASP ( G raphics A PI for S tudents of P ython) will enable us to write programs involving graphics. Before you can use GASP, it needs to be installed on your machine. If you are running Ubuntu GNU/Linux, see GASP in Appendix A . Current instructions for installing GASP on other platforms can be found at http://dev.laptop.org/pub/gasp/downloads .
To start gasp after it is installed, try the following:
from gasp import*
begin_graphics()
Circle((200,200),60)
Line((100,400),(580,200))
Box((400,350),120,100)
end_graphics()
按照原书的PYTHON的版本我用PYTHON2.5根本无法 from gasp import *,解释器报错:模块不存在,可是我明明看到模块在SITE_PACKAGES.不知道是不是配置问题,到现在还没有弄清楚.
然后我试下PYTHON2.4,可以FROM GASP IMPORT*拉,不过仍然有问题:
Circle
((
200
,
200
),
60
)
Traceback (most recent call last):
File "<pyshell#3>", line 1, in -toplevel-
#这句话是什么意思?
Circle((200,200),60)
File "D:\python\lib\site-packages\gasp-0.4.0-py2.4.egg\gasp\api.py", line 170, in __repr__
return "A Circle instance at (%d, %d) with a radius of %d" %(self.x, self.y, self.radius)
AttributeError: Circle instance has no attribute 'x'
#这句话是什么意思?
前几天和 猫猫 讨论下,我去看了源代码:
class Circle(Shape):
def __init__(self, center, radius, filled=False,
color=(0,0,0),
thickness=1):
Shape.__init__(self, center, filled, color, thickness)
self.radius = radius
backend.create_circle(self)
def __repr__(self):
return "A Circle instance at (%d, %d) with a radius of %d" %(self.x, self.y, self.radius)
请教各位这代码有问题吗?
需要说明的是 Line (( 100 , 400 ), ( 580 , 200 )) 的时候解释器OK!
LINE的源代码:
class Line:
def __init__(self, start, end, color=(0,0,0)):
self.start = Point(start)
self.end = Point(end)
self.color = color
backend.create_line(self)
def __repr__(self):
return "A Line instance from (%d,%d) to (%d,%d)" %(self.x, self.y, self.end.x, self.end.y)
请各位给出出主意,多谢拉!急死拉!
Zeuux © 2024
京ICP备05028076号
回复 電波系山寨文化科学家 2009年09月24日 星期四 18:57