May i customize basic operator (such as 1==3)?

Robert Kern robert.kern at gmail.com
Wed Feb 22 01:38:52 EST 2006


kanchy kang wrote:
> many people write test cases with python scripts.
> in these test scripts, there are many validation statements,
> for example, in unittest, failUnless(a == b),(a/b may be stringType or
> intType...)
> 
> during running test scripts, if there is one exception raised from
> failUnless, i still do not know a =?, b= ?... i have to add one statment
> "print a" or "print b" again...
> 
> as i know, there are many validation statements if using python as one
> test tool...

So why don't you just do something like this:

  self.failUnless(a == b, "%s != %s" % (a,b))

As a bonus, that will only print something if the test fails rather than spewing
out a whole bunch of text that's irrelevant when the tests pass.

> i think my suggestion or requirement may benefit users greatly...

Python will never grow the ability to modify methods on the builtin types. We've
discussed several times before, and you can search the archives of this list if
you want more information why this is so.

-- 
Robert Kern
robert.kern at gmail.com

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter




More information about the Python-list mailing list