我正尝试编写Python 2.7的cod,通过在需求更改的情况下提供默认值的同时删除参数顺序来进行扩展。这里是我的代码:在Python中同时删除参数顺序并提供默认值的最安全的方法
# 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 is a problem with the HTML")
# call:
mailer=Mailer(
subject="Subject goes here",
password="password",
mailing_list=("[email protected]", "[email protected]","[email protected]"),
mailing_list=("[email protected]", "[email protected]"),
from_address="[email protected]",
sector=Sector()
)
我还是新的语言,所以,如果有更好的方式来做到这一点,我真的很想知道。提前致谢。