我正嘗試編寫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()
)
我還是新的語言,所以,如果有更好的方式來做到這一點,我真的很想知道。提前致謝。