On 27/09/2016 17:49, Steve D'Aprano wrote:
I have a class that takes a bunch of optional arguments. They're all
optional, with default values of various types. For simplicity, let's say
some are ints and some are floats:
class Spam:
def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,
You could use `attrs` for this along with the convert option, if you're
open to receiving mixed arguments:
>>> @attr.s
... class C(object):
... x = attr.ib(convert=int)
>>> o = C("1")
>>> o.x
1
https://attrs.readthedocs.io/en/stable/examples.html#conversion
On Tue, Sep 27, 2016, 16:51 Steve D'Ap
On Wed, 28 Sep 2016 01:49:56 +1000, Steve D'Aprano wrote:
> I have a class that takes a bunch of optional arguments. They're all
> optional, with default values of various types. For simplicity, let's
> say some are ints and some are floats:
>
>
> class Spam:
> def __init__(self, bashful=10.
On Tue, 27 Sep 2016 10:30:05 -0700, Paul Rubin wrote:
> Chris Angelico writes:
>> Can you elaborate on what "GoF builder" means? Presumably it's a
>> special case of the builder pattern,
>
> I think it just means the usual builder pattern, from the Design
> Patterns book by the so-called Gang o
Chris Angelico writes:
> Can you elaborate on what "GoF builder" means? Presumably it's a
> special case of the builder pattern,
I think it just means the usual builder pattern, from the Design
Patterns book by the so-called Gang of Four (GoF).
--
https://mail.python.org/mailman/listinfo/python
On Wed, Sep 28, 2016 at 3:08 AM, Gerald Britton
wrote:
>>
>> I have a class that takes a bunch of optional arguments. They're all
>> optional, with default values of various types. For simplicity, let's say
>> some are ints and some are floats: class Spam:
>> def __init__(self, bashful=10.0, doc=2
Steve D'Aprano writes:
> class Spam:
> def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,
> grumpy=40, happy=50, sleepy=60, sneezy=70):
> # the usual assign arguments to attributes dance...
> self.bashful = bashful
> self.doc = doc
> # etc.
>
> I have a class that takes a bunch of optional arguments. They're all
> optional, with default values of various types. For simplicity, let's say
> some are ints and some are floats: class Spam:
> def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,
> grumpy=40, happy=50, sleepy=60, sneezy=70)
On Wed, Sep 28, 2016 at 1:49 AM, Steve D'Aprano
wrote:
> @classmethod
> def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0',
> grumpy='40', happy='50', sleepy='60', sneezy='70'):
> bashful = float(bashful)
> doc = float(doc)
> dopey =
Steve D'Aprano :
> def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,
> grumpy=40, happy=50, sleepy=60, sneezy=70):
> [...]
>
> @classmethod
> def from_strings(cls, bashful='10.0', doc='20.0', dopey='30.0',
> grumpy='40', happy='50', sleepy='
I have a class that takes a bunch of optional arguments. They're all
optional, with default values of various types. For simplicity, let's say
some are ints and some are floats:
class Spam:
def __init__(self, bashful=10.0, doc=20.0, dopey=30.0,
grumpy=40, happy=50, sleepy=60
11 matches
Mail list logo