Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59846

Re: When to use assert

From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: When to use assert
Date 2013-11-18 10:02 +0000
References <528871d5$0$29975$c3e8da3$5496439d@news.astraweb.com> <roy-8BDD06.08334817112013@news.panix.com> <CAHVvXxQYwgnmDw48kdFw258v6Sf_+2gnZna8_=0-_t_4xSduCA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2830.1384768972.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 18/11/2013 09:50, Oscar Benjamin wrote:
> On 17 November 2013 13:33, Roy Smith <roy@panix.com> wrote:
>>
>> So, I stick "assert 0" in the code an re-run the program to see if I get
>> an AssertionError.  If I do, then I know the code is being run.  If I
>> don't then I know it's not.  Either way, I know more about what's going
>> on than I did before.  Once I know what's going on, I remove the assert.
>
> If the program is invoked from a terminal I would probably go with
> 'import pdb; pdb.set_trace()' rather than 'assert 0'. Then you can
> check much more than whether or not the code is being executed. It's a
> bit more to type but I type it so often that I can now type it *really
> fast*.
>
>
> Oscar
>

If I used something that often I'd either cut and paste it or have a key 
combination set up to insert it automatically.  Or get my man to type it 
up for me :)

-- 
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

When to use assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-17 07:35 +0000
  Re: When to use assert Tim Chase <python.list@tim.thechases.com> - 2013-11-17 06:50 -0600
    Re: When to use assert Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-18 00:52 +0000
  Re: When to use assert Roy Smith <roy@panix.com> - 2013-11-17 08:33 -0500
    Re: When to use assert Robert Day <robertkday@gmail.com> - 2013-11-18 08:20 +0000
    Re: When to use assert Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-11-18 09:50 +0000
    Re: When to use assert Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-18 10:02 +0000
    Re: When to use assert Tim Chase <python.list@tim.thechases.com> - 2013-11-18 05:44 -0600

csiph-web