Re: Friday Finking: Poly more thick

2020-02-29 Thread MRAB
On 2020-03-01 02:08, Christman, Roger Graydon wrote: DL Neil asked: How does one code a function/method signature so that it will accept either a set of key-value pairs, or the same data enclosed as a dict, as part of a general-case and polymorphic solution? Will this do for you? def any_as

Re: Friday Finking: Poly more thick

2020-02-29 Thread Christman, Roger Graydon
Emending my own note from moments ago: def any_as_dict(*args, **kwargs): if len(args) == 0: my_dict = kwargs elif type(args[0]) == type(dict()): my_dict = args[0] else: my_dict = dict(args[0]) print(type(my_dict),my_dict) >>> any_as_dict(a=1,b=2) {'a': 1, 'b': 2} >>> any_as_dict({'a':1, 'b':2}

Re: Friday Finking: Poly more thick

2020-02-29 Thread Christman, Roger Graydon
DL Neil asked: > How does one code a function/method signature so that > it will accept either a set of key-value pairs, > or the same data enclosed as a dict, as part of > a general-case and polymorphic solution? Will this do for you? def any_as_dict(*args, **kwargs): if len(args) == 0: my_dic

Friday Finking: Poly more thick

2020-02-28 Thread DL Neil via Python-list
How does one code a function/method signature so that it will accept either a set of key-value pairs, or the same data enclosed as a dict, as part of a general-case and polymorphic solution? Wikipedia: polymorphism is the provision of a single interface to entities of different types. ( https