Safest way to remove argument order and provide default values at the same time in Python -
i trying write python 2.7 cod easier scale removing argument order while providing default values in case requirements change. here code:
# class: class mailer(object): def __init__(self, **args): self.subject=args.get('subject', none) self.mailing_list=args.get('mailing_list', none) self.from_address=args.get('from_address', none) self.password=args.get('password', none) self.sector=args.get('sector', "there problem html") # call: mailer=mailer( subject="subject goes here", password="password", mailing_list=("email@email.com", "email@email.com","email@email.com"), mailing_list=("email@email.com", "email@email.com"), from_address="email@email.com", sector=sector()
)
i'm still new language if there better way achieve this, i'd know. in advance.
try way of initialize class:
class mailer(object): def __init__(self, **args): k in args: self.__dict__[k] = args[k]
Comments
Post a Comment