How can I catch misnamed variables?

Discussion in 'Python' started by John Gordon, Feb 10, 2012.

  1. John Gordon

    John Gordon Guest

    Recently I was been bitten by some stupid errors in my code, and I'm
    wondering if there's a simple way to catch them.

    One error was of the form:

    my_object.some_function()

    ... when I hadn't declared an object named "my_object".

    The other error was similar:

    x = my_module.CONSTANT

    ... when I hadn't imported my_module.

    Of course both of these errors were deep inside a long-running function
    call, so it took a while for them to crop up.

    Is there an automated way to catch errors like these? I'm using the
    compileall module to build my program and it does catch some errors
    such as incorrect indentation, but not errors like the above.

    --
    John Gordon A is for Amy, who fell down the stairs
    B is for Basil, assaulted by bears
    -- Edward Gorey, "The Gashlycrumb Tinies"
    John Gordon, Feb 10, 2012
    #1
    1. Advertising

  2. On 10 February 2012 21:06, John Gordon <> wrote:
    > Recently I was been bitten by some stupid errors in my code, and I'm
    > wondering if there's a simple way to catch them.
    >
    > One error was of the form:
    >
    >  my_object.some_function()
    >
    > .. when I hadn't declared an object named "my_object".
    >
    > The other error was similar:
    >
    >  x = my_module.CONSTANT
    >
    > .. when I hadn't imported my_module.
    >
    > Of course both of these errors were deep inside a long-running function
    > call, so it took a while for them to crop up.
    >
    > Is there an automated way to catch errors like these?  I'm using the
    > compileall module to build my program and it does catch some errors
    > such as incorrect indentation, but not errors like the above.


    There's pychecker and pylint

    --
    Arnaud
    Arnaud Delobelle, Feb 10, 2012
    #2
    1. Advertising

  3. John Gordon

    Kev Dwyer Guest

    John Gordon wrote:

    > Recently I was been bitten by some stupid errors in my code, and I'm
    > wondering if there's a simple way to catch them.
    >

    <snip>


    Pyflakes is another static checker that can catch these sorts of errors.

    Cheers,

    Kev
    Kev Dwyer, Feb 10, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Black
    Replies:
    8
    Views:
    4,152
    Xenos
    Aug 20, 2004
  2. Adam
    Replies:
    9
    Views:
    567
    red floyd
    Feb 2, 2006
  3. Replies:
    9
    Views:
    936
  4. Marteno Rodia

    catch doesn't catch a thrown exception

    Marteno Rodia, Aug 3, 2009, in forum: Java
    Replies:
    5
    Views:
    564
    Daniel Pitts
    Aug 5, 2009
  5. PerlFAQ Server
    Replies:
    0
    Views:
    131
    PerlFAQ Server
    Feb 28, 2011
Loading...

Share This Page