Steven D'Aprano wrote:
> On Fri, 12 Jun 2015 16:53:08 +0100, Paulo da Silva wrote:
>
>> I would like to do something like this:
>>
>> class C:
>> def __init__(self,**parms):
>> ...
>>
>> c=C(f1=1,f2=None)
>>
>> I want to have, for the object
>> self.f1=1
>> self.f2=None
>>
>> for an arbitrary
On 13-06-2015 02:25, Steven D'Aprano wrote:
> On Fri, 12 Jun 2015 16:53:08 +0100, Paulo da Silva wrote:
>
...
>
> You should use SimpleNamespace, as Peter suggests, but *not* subclass it.
> If you subclass it and add methods:
>
> class C(SimpleNamespace):
> def foo(self, arg):
> pr
On 12-06-2015 20:12, Peter Otten wrote:
> Paulo da Silva wrote:
>
>> On 12-06-2015 17:17, Peter Otten wrote:
>>> Paulo da Silva wrote:
>>>
>> ...
...
> It *is* a class, and by making C a subclass of SimpleNamespace C inherits
> the initialiser which does the actual work of updating the __dict__
On Fri, 12 Jun 2015 16:53:08 +0100, Paulo da Silva wrote:
> I would like to do something like this:
>
> class C:
> def __init__(self,**parms):
> ...
>
> c=C(f1=1,f2=None)
>
> I want to have, for the object
> self.f1=1
> self.f2=None
>
> for an arbitrary number of parame
Paulo da Silva wrote:
> On 12-06-2015 17:17, Peter Otten wrote:
>> Paulo da Silva wrote:
>>
> ...
>
>>
> import types
> class C(types.SimpleNamespace):
>> ... pass
>> ...
> c = C(f1=1, f2=None)
> c
>> C(f1=1, f2=None)
>>
>
> Thanks for all your explanations.
> This solutio
On 12-06-2015 17:17, Peter Otten wrote:
> Paulo da Silva wrote:
>
...
>
import types
class C(types.SimpleNamespace):
> ... pass
> ...
c = C(f1=1, f2=None)
c
> C(f1=1, f2=None)
>
Thanks for all your explanations.
This solution works. Would you please detail a little on
On 12-06-2015 17:17, gst wrote:
> Le vendredi 12 juin 2015 11:53:24 UTC-4, Paulo da Silva a écrit :
> in the __init__, simply do:
>
> self.__dict__.update(**parms)
>
> regards,
>
Ok. Thanks.
--
https://mail.python.org/mailman/listinfo/python-list
Le vendredi 12 juin 2015 11:53:24 UTC-4, Paulo da Silva a écrit :
> I would like to do something like this:
>
> class C:
> def __init__(self,**parms):
> ...
>
> c=C(f1=1,f2=None)
>
> I want to have, for the object
> self.f1=1
> self.f2=None
>
> for an arbitrary number of
Paulo da Silva wrote:
> I would like to do something like this:
>
> class C:
> def __init__(self,**parms):
> ...
>
> c=C(f1=1,f2=None)
>
> I want to have, for the object
> self.f1=1
> self.f2=None
>
> for an arbitrary number of parameters.
>
> What is the best way to achieve this?
Use a dict
I would like to do something like this:
class C:
def __init__(self,**parms):
...
c=C(f1=1,f2=None)
I want to have, for the object
self.f1=1
self.f2=None
for an arbitrary number of parameters.
What is the best way to achieve this?
Thanks
--
https://mail.python
10 matches
Mail list logo