Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Q on classes
#2
It is saying 4 because it requires 4. Clock.set_time() is an instance method. The first argument must be an instance of Clock. You are treating it like a static method.

I would rename this method __str__:
    def get_time(self):
        return '{:02d}:{:02d}:{:02d}'.format(self.hours, self.minutes, self.seconds)
I would also use f'string formatting because format() is old and not great, and also because you use f'string formatting everywhere else in your program.
    def __str__(self):
        return f'{self.hours:02d}:{self.minutes:02d}:{self.seconds:02d}'
But I would not use f'string formatting here.
print(f'Updating RTC...')
And I would use unpacking here:
            year = cet[0]
            month = cet[1]
            day = cet[2]
            hours = cet[3]
            minutes = cet[4]
            seconds = cet[5]
            weekday = cet[6]
year, month, day, hours, minutes, seconds, weekday, *_ = cet
Reply


Messages In This Thread
Q on classes - by ebolisa - Mar-06-2023, 03:17 PM
RE: Q on classes - by deanhystad - Mar-06-2023, 03:21 PM
RE: Q on classes - by ebolisa - Mar-06-2023, 03:21 PM
RE: Q on classes - by ebolisa - Mar-06-2023, 03:24 PM
RE: Q on classes - by deanhystad - Mar-06-2023, 04:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using classes? Can I just use classes to structure code? muteboy 5 5,277 Nov-01-2017, 04:20 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020