Menu

code analysis & __name__ var

Joey Liu
2008-10-09
2013-03-15
  • Joey Liu

    Joey Liu - 2008-10-09

    I always get the following problems

    Description    Resource    Path    Location    Type
    Undefined variable: __name__    example.py    test/src/root/nested    line 0    PyDev Problem

    for every module I have:
    if __name__ == '__main':
        DoTestCode()

    But Pydev Extensions say Undefined variable: __name__
    How can I fix that?

     
    • Fabio Zadrozny

      Fabio Zadrozny - 2008-10-10

      Strange, __name__ should be gotten from builtins as other tokens such as False, True, etc.

      Do you have some error in your error log? Other names such as 'True', 'False' are correctly found?

      Cheers,

      Fabio

       
    • Joey Liu

      Joey Liu - 2008-10-10

      Strange, I restart my system and then create a new module. I type on the first line if __name__ == '__main__': it still has the same error message, and then I type on the second line somevar = True and save the file, the error message suddenly disappear.

      After all of these action, whatever I do, the error message no longer appear.

      BTW, Pylint is disabled.

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2008-10-10

        Humm, what could happen is that the 1st time the shell still wasn't started, so, pydev just goes on so that your system doesn't appear halted, so, the builtin vars are not available... and then on the 2nd request, with the shell started, the new request for analysis is able to gather those tokens.

        Cheers,

        Fabio

         
    • Jean-Marie Rata

      Jean-Marie Rata - 2008-10-13

      I just begin working with Eclipse and Pydev, and have the same problem:
      __name__  is cataloged as undefined,

      ans when I add somevar = True, I get

      Undefined variable: True

      For longer programs, range, None, Frame, etc.  are taken as Undefined variables…

      Anyway, the programs work all right (I tested some longer programs already tested with IDLE, I am working on a Mac PowerPC G5 )

      I tried to restart, but with  always the same result…

       
      • Fabio Zadrozny

        Fabio Zadrozny - 2008-10-13

        Do you have some error in your error log? -- that usually happens when there's some error when spawning the shell for dynamic analysis (the usual cause is having a firewall enabled that's blocking communication).

        Cheers,

        Fabio