在Ubuntu中使用Geany调用python类

2024-09-29 19:29:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我在ubuntu中使用Geany for editor python,并创建了一个包含该类的文件。你知道吗

这是我的档案。时间1.py

class Time:

    def __int__(self):
        self.hour = 0
        self.minute = 0
        self.second = 0

    def printMilitary(self):
        print "%.2d:%.2d:%.2d" % \
          (self.hour, self.minute, self.second),

    def printStandard(self):

        standardtime = ""
        if self.hour == 0 or self.hour == 12:
            standardTime += "12:"
        else:
            standardTime += "%d:" % ( self.hour % 12 )
        standardTime += "%.2d:%.2d" % ( self.minute, self.second )

        if self.hour < 12:
            standardTime += " AM"
        else:
            standardTime += " PM"
        print standardTime,

所以我把它叫来了我的时间.py你知道吗

from Time1 import Time

time1 = Time()

print "The attributes of time1 are: "
print "time1.hour:", time1.hour
print "time1.minute:", time1.minute
print "time1.second:", time1.second

之后我试着运行这个脚本。但我错了。这就是错误所在

The attributes of time1 are: time1.hour: Traceback (most recent call last): File "untitled.py", line 31, in print "time1.hour:", time1.hour AttributeError: Time instance has no attribute 'hour'

你能帮我吗


Tags: thepyselfiftimedef时间else

热门问题