On Fri, Nov 7, 2008 at 7:02 PM, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
wrote:
>> What if I need the parse method to be called in other parts of the
>> program?
>
> I don't understand!? Then you call it from those other parts.
Yes, you're right. Don't know why, but I was thinking to use
@cl
Duncan Booth wrote:
Mr.SpOOn <[EMAIL PROTECTED]> wrote:
Now I must pass a and b to the main constructor and calculate them in
the classmethods.
class foo:
def __init__(self, a, b):
self.a = a
self.b = b
@classmethod
def from_string(self, ..):
...
On Fri, 07 Nov 2008 17:23:21 +0100, Mr.SpOOn wrote:
> On Fri, Nov 7, 2008 at 4:16 PM, Duncan Booth
> <[EMAIL PROTECTED]> wrote:
>> There is a really big advantage to being explicit in this situation:
>> you no longer have to make sure that all your constructors use a unique
>> set of types. Consid
On Fri, Nov 7, 2008 at 4:16 PM, Duncan Booth
<[EMAIL PROTECTED]> wrote:
> There is a really big advantage to being explicit in this situation: you no
> longer have to make sure that all your constructors use a unique set of
> types. Consider:
>
> class Location(object):
>def __init__(self, lat,
On Fri, 07 Nov 2008 15:16:29 +, Duncan Booth wrote:
> 'from_string' is a bad name here for your factory method: you should try
> to make it clear what sort of string is expected.
When I use a `from_string()` factory I usually make sure it can parse the
`str()` form of that type or that there
Mr.SpOOn <[EMAIL PROTECTED]> wrote:
> Now I must pass a and b to the main constructor and calculate them in
> the classmethods.
>
> class foo:
> def __init__(self, a, b):
> self.a = a
> self.b = b
>
> @classmethod
> def from_string(self, ..):
> ...
>
On Thu, Nov 6, 2008 at 11:00 PM, Ben Finney
<[EMAIL PROTECTED]> wrote:
> Yes, the main reason is that it kills duck typing. The initialiser
> should *use* the parameters passed, and allow exceptions to propagate
> back to the caller if the parameters don't behave as expected.
>
> Another good reaso
On Thu, Nov 6, 2008 at 11:00 PM, Ben Finney
<[EMAIL PROTECTED]> wrote:
> Yes, the main reason is that it kills duck typing. The initialiser
> should *use* the parameters passed, and allow exceptions to propagate
> back to the caller if the parameters don't behave as expected.
>
> Another good reaso
Arnaud Delobelle <[EMAIL PROTECTED]> writes:
> Ben Finney <[EMAIL PROTECTED]> writes:
> [...]
> > All you need to know to understand the above is that it will have
> > essentially the same result as:
> >
> > class A(object):
> > # ...
> >
> > def _from_string(cls, s):
> >
Larry Bates <[EMAIL PROTECTED]> writes:
> Is there some reason not to use something like the following?
>
> class foo:
> def __init__(self, val):
> self.a = 0
> self.b = 0
>
> if isinstance(val, basestring):
> #
> # do something to calculate "a
Mr.SpOOn <[EMAIL PROTECTED]> writes:
> class foo:
> def __init__(self, a, b):
> self.a = a
> self.b = b
>
> @classmethod
> def from_string(self, ..):
> ...
> ...
>
> What I mean is: I can't use anymore __init__ as the default
> constructor, but I
Ben Finney <[EMAIL PROTECTED]> writes:
[...]
> All you need to know to understand the above is that it will have
> essentially the same result as:
>
> class A(object):
> # ...
>
> def _from_string(cls, s):
> # ...
> return cls(a, b, c)
> from_stri
Mr.SpOOn <[EMAIL PROTECTED]> writes:
> On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
> wrote:
> > class A(object):
> >def __init__(self, a, b, c):
> >self.a = a
> ># ...
> >
> >@classmethod
> >def from_string(cls, s):
> ># ...
> >
Mr.SpOOn wrote:
On Thu, Nov 6, 2008 at 7:44 PM, Tim Golden <[EMAIL PROTECTED]> wrote:
While that's no bad thing, you don't really need to do
that simply to understand these examples: they're just
saying "do whatever you need to to make these method
class methods, not instance methods".
Yes.
I
On Thu, Nov 6, 2008 at 7:44 PM, Tim Golden <[EMAIL PROTECTED]> wrote:
> While that's no bad thing, you don't really need to do
> that simply to understand these examples: they're just
> saying "do whatever you need to to make these method
> class methods, not instance methods".
Yes.
I think this
Mr.SpOOn wrote:
On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
wrote:
class A(object):
def __init__(self, a, b, c):
self.a = a
# ...
@classmethod
def from_string(cls, s):
# ...
return cls(a, b, c)
Thanks.
I think it's time to
On Thu, Nov 6, 2008 at 4:59 PM, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]>
wrote:
> class A(object):
>def __init__(self, a, b, c):
>self.a = a
># ...
>
>@classmethod
>def from_string(cls, s):
># ...
>return cls(a, b, c)
Thanks.
I think it's time to st
On Thu, 06 Nov 2008 16:49:08 +0100, Mr.SpOOn wrote:
> I know there can be only one __init__ method (at least, I think).
>
> Often I need an object to be created in different ways, for example
> passing a string as argument, or an integer, or another object. To
> achieve this I put the default val
Mr.SpOOn wrote:
Hi,
I know there can be only one __init__ method (at least, I think).
Often I need an object to be created in different ways, for example
passing a string as argument, or an integer, or another object. To
achieve this I put the default value of the arguments to None and then
I so
Hi,
I know there can be only one __init__ method (at least, I think).
Often I need an object to be created in different ways, for example
passing a string as argument, or an integer, or another object. To
achieve this I put the default value of the arguments to None and then
I some if...elif insid
20 matches
Mail list logo