assert versus print [was Re: The curious behavior of integer objects]
Ron Adam
rrr at ronadam.com
Tue Jan 16 07:32:12 EST 2007
Carl Banks wrote:
> Ron Adam wrote:
>> There have been times where I would like assert to be a little more assertive
>> than it is. :-)
>>
>> ie.. not being able to turn them off with the -0/-00 switches, and having them
>> generate a more verbose traceback.
>
> Personally, I'd rather see it get less assertive, i.e., having it only
> work in a special debugging mode. That way people who haven't RTFM
> don't use it to make sure their input is correct.
>
>
> Carl Banks
Well, the manual could be improved in this area quite a bit. There also really
need to be easier to find examples for both assert and warnings use.
But it does only work in a special debugging mode. Didn't you RTFM? ;-)
http://docs.python.org/ref/assert.html
It just happens this mode is turned on by default. So you would like this to be
turned off by default. I agree. I think there may be a way to change pythons
default startup behavior for this.
Warnings generated by warn() on the other hand can be silenced, but not
completely ignored. But I also think they could be a more useful and flexible
tool for debugging purposes.
http://docs.python.org/lib/warning-functions.html
I have to admit that part of why assert seems wrong to me is the meaning of the
word implies something you shouldn't be able to ignore. While warnings seem
like something that can be disregarded.
I think maybe the best way to use both may be to combine them...
assert <condition> warn(...)
But I'm not sure that doesn't have problems of it's own. <shrug>
Cheers,
Ron
More information about the Python-list
mailing list