I used Geany for editor python in ubuntu, and I created a file containing the class.
this my file. Time1.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,
so I called it in mytime.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
after that I tried to run this script. but I got error. This the error
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’
can you help me
__int__needs to be__init__.