Aahz wrote:
In article ,
Jean-Michel Pichavant wrote:
class A:
def __init__(self, foo = None, bar = None):
if len(foo) > 5:
raise ValueError('foo cannot exceed 5 characters')
Bad Idea -- what happens when foo is None?
You're right.
That perfectly illustr
In article ,
Jean-Michel Pichavant wrote:
>
>class A:
>def __init__(self, foo = None, bar = None):
>if len(foo) > 5:
> raise ValueError('foo cannot exceed 5 characters')
Bad Idea -- what happens when foo is None?
--
Aahz (a...@pythoncraft.com) <*> htt
In article ,
Chris Rebert wrote:
>On Mon, Jan 4, 2010 at 10:17 AM, Albert van der Horst
> wrote:
>
>> This triggers a question: I can see the traceback, but it
>> would be much more valuable, if I could see the arguments
>> passed to the functions. Is there a tool?
>
>print(locals()) #this actual
En Mon, 04 Jan 2010 15:17:04 -0300, Albert van der Horst
escribió:
This triggers a question: I can see the traceback, but it
would be much more valuable, if I could see the arguments
passed to the functions. Is there a tool?
Yes, the cgitb module [1]. Despite its name it's a general purpose
Steve Holden wrote:
What's the exact reason for requiring that a creator argument be of a
specific type? So operations on the instances don't go wrong? Well, why
not just admit that we don't have control over everything, and just *let
things go wrong* when the wrong type is passed?
Because s
On Mon, Jan 4, 2010 at 10:17 AM, Albert van der Horst
wrote:
> This triggers a question: I can see the traceback, but it
> would be much more valuable, if I could see the arguments
> passed to the functions. Is there a tool?
print(locals()) #this actually gives the bindings for the entire local
In article ,
Steve Holden wrote:
>
>What's the exact reason for requiring that a creator argument be of a
>specific type? So operations on the instances don't go wrong? Well, why
>not just admit that we don't have control over everything, and just *let
>things go wrong* when the wrong type is pa
On 12/22/2009 8:52 PM, Bruno Desthuilliers wrote:
Steve Holden a écrit :
(snip)
What's the exact reason for requiring that a creator argument be of a
specific type? So operations on the instances don't go wrong? Well, why
not just admit that we don't have control over everything, and just *let
t
Bruno Desthuilliers wrote:
> Steve Holden a écrit :
> (snip)
>> What's the exact reason for requiring that a creator argument be of a
>> specific type? So operations on the instances don't go wrong? Well, why
>> not just admit that we don't have control over everything, and just *let
>> things go w
Steve Holden a écrit :
(snip)
What's the exact reason for requiring that a creator argument be of a
specific type? So operations on the instances don't go wrong? Well, why
not just admit that we don't have control over everything, and just *let
things go wrong* when the wrong type is passed?
va
Denis Doria a écrit :
Hi;
I'm checking the best way to validate attributes inside a class. Of
course I can use property to check it, but I really want to do it
inside the __init__:
If you use a property, you'll have the validation in the initializer AND
everywhere else too. If you care about
On Tue, 22 Dec 2009 00:18:21 +, r0g wrote:
> Yikes, glad to be set me straight on that one! Thanks :) It's a pity
> though, I really like the way it reads. Is there anything similar with
> ISN'T disabled when optimizations are turned on?
Yes: an explicit test-and-raise.
if not condition:
r0g wrote:
> Steven D'Aprano wrote:
>> On Mon, 21 Dec 2009 21:49:11 +, r0g wrote:
>>
>>> I use assertions myself e.g.
>>>
>> foo = "123456"
>> assert len(foo) <= 5
>>> Traceback (most recent call last):
>>> File "", line 1, in
>>> AssertionError
>>>
>>>
>>> Dunno if this would be con
Steven D'Aprano wrote:
> On Mon, 21 Dec 2009 21:49:11 +, r0g wrote:
>
>> I use assertions myself e.g.
>>
> foo = "123456"
> assert len(foo) <= 5
>> Traceback (most recent call last):
>> File "", line 1, in
>> AssertionError
>>
>>
>> Dunno if this would be considered good or bad prog
On Mon, 21 Dec 2009 21:49:11 +, r0g wrote:
> I use assertions myself e.g.
>
foo = "123456"
assert len(foo) <= 5
> Traceback (most recent call last):
> File "", line 1, in
> AssertionError
>
>
> Dunno if this would be considered good or bad programming practice by
> those more e
On 12/22/2009 4:41 AM, Denis Doria wrote:
Hi;
I'm checking the best way to validate attributes inside a class. Of
course I can use property to check it, but I really want to do it
inside the __init__:
class A:
def __init__(self, foo, bar):
self.foo = foo #check if foo is correct
On Mon, 21 Dec 2009 09:41:22 -0800, Denis Doria wrote:
> Hi;
>
> I'm checking the best way to validate attributes inside a class.
There is no "best way", since it depends on personal taste.
> Of
> course I can use property to check it, but I really want to do it inside
> the __init__:
If you
Denis Doria wrote:
> Hi;
>
> I'm checking the best way to validate attributes inside a class. Of
> course I can use property to check it, but I really want to do it
> inside the __init__:
>
> class A:
> def __init__(self, foo, bar):
> self.foo = foo #check if foo is correct
>
* Denis Doria:
I thought in something like:
class A:
def __init__(self, foo = None, bar = None):
set_foo(foo)
self._bar = bar
def set_foo(self, foo):
if len(foo) > 5:
raise
_foo = foo
foo = property(setter = set_foo)
But looks too much
Denis Doria wrote:
Hi;
I'm checking the best way to validate attributes inside a class. Of
course I can use property to check it, but I really want to do it
inside the __init__:
class A:
def __init__(self, foo, bar):
self.foo = foo #check if foo is correct
self.bar = bar
Al
On Mon, Dec 21, 2009 at 9:41 AM, Denis Doria wrote:
> All examples that I saw with property didn't show a way to do it in
> the __init__. Just to clarify, I don't want to check if the parameter
> is an int, or something like that, I want to know if the parameter do
> not use more than X chars; an
Hi;
I'm checking the best way to validate attributes inside a class. Of
course I can use property to check it, but I really want to do it
inside the __init__:
class A:
def __init__(self, foo, bar):
self.foo = foo #check if foo is correct
self.bar = bar
All examples that I saw
22 matches
Mail list logo