[Tutor] Classes in multiple files - code included

Steven D'Aprano steve at pearwood.info
Thu Apr 4 11:40:46 CEST 2013


On 04/04/13 13:12, Phil wrote:
> On 04/04/13 11:58, Steven D'Aprano wrote:
>> On 04/04/13 12:47, Phil wrote:
>>
>>> And this is the error message;
>>>
>>> "global name 'Ui_satListDialog' is not defined"
>>
>> On its own, that is almost useless.
>>
>> Python gives you more debugging information than that: it gives you a
>> complete traceback, which includes the actual line of code causing the
>> problem. We don't even know which file gives the error, let alone which
>> line of code!
>>
>> When you try to run the program, you will get an error. Please copy and
>> paste the *complete* traceback, starting with the line "Traceback (most
>> recent call last)" all the way to the bottom. It will show you which
>> file contains the error, what type of error it is, and which line fails.
>>
>
> Thank you for your reply Steven,
>
> As useless as the error message may be it's the only one given.


You have misunderstood me. In your email, quoted above, you pasted ONLY the
error message "global name 'Ui_satListDialog' is not defined".

But now, following my prompting, you pasted the ENTIRE traceback:

> phil at Asus:~/Eric/Pest$ python pest.py
> Traceback (most recent call last):
>    File "/home/phil/Eric/Pest/ui/mainwindow.py", line 57, in on_actionList_triggered
>      dialog = Ui_satListDialog.SatelliteListDialog(self)
> NameError: global name 'Ui_satListDialog' is not defined
> ^CTraceback (most recent call last):
>    File "pest.py", line 9, in <module>
>      sys.exit(app.exec_())

Notice how much more information there is? We learn:

* the error is occurring in your mainwindow.py file

* on line 57

* in the function or method "on_actionList_triggered"

* with the exact line "dialog = Ui_satListDialog.SatelliteListDialog(self)"

* which gives a NameError (as apposed to any of dozens of different sorts of error)

* with the specific error message "global name 'Ui_satListDialog' is not defined"

(and then there is a further error when you try to quit the app with Ctrl-C, but one thing at a time).

One of the most critical skills for a programmer is to learn how to diagnose errors. Trying to diagnose the error from just the error message is a bit like telling the doctor you have a pain, but refusing to tell where the pain is, what sort of pain, how long you've had it, or under what circumstances it comes and goes.

Debugging, at times, is hard enough even with the assistance of full tracebacks. You'll soon learn to appreciate them.



-- 
Steven


More information about the Tutor mailing list