0
class Doctor(object):
    def __init__ (self, name, weekdays=None, weekend=None):
        self.name=name
        self.weekdays=weekdays
        self.weekend=weekend

    def set_weekdays(self,weekdaysshift):
        self.weekdays=weekdaysshift

    def set_weekend(self,weekendshifts):
        self.weekend=weekendshifts

    def get_name(self):
        return self.name

    def get_weekdaysshift(self):
        return self.weekdays

    def get_weekendshifts(self):
        return self.weekend

    def __str__(self):
        return 'Doctor: {}'.format str((self.name))

Hi, I'm new to Python and just learning it for the last two months and I was wondering if I can write a script to create monthly duty/shift list. I have no problem creating a class and istances but I was wondering if I can create instances of the class based on user input.

So when I write my script it should be something like that:

Name of the doctor:

Shifts in weekdays:

Shifts on weekend:

and use that user input to create an instance of the class.

This is not an exact duplicate of a previosly asked question. There must be a way to create an instance without using dictionary and add it to dictionary if user wants multiple instances.

Thanks for the help :)

  • I don't think that it's a duplicate because: 1- Yes it tells how to create an instance by user input but it's very complicated and I think that's not the Pythonic way to do it 2- I found this answer: https://stackoverflow.com/questions/32721580/example-of-class-with-user-input but couldn't figure it out how @classmethod works. Could somebody please explain me please? – mustafaaydinol Oct 01 '17 at 20:30
  • You don't need a class method really, it can just be a function. – juanpa.arrivillaga Oct 01 '17 at 22:18
  • @COLDSPEED could you please explain how can I create instance by user input without using a dictionary and creating multiple instances please? – mustafaaydinol Oct 02 '17 at 17:00

0 Answers0