[Tutor] Class errors
cs at zip.com.au
Thu Jan 22 22:31:27 CET 2015
On 22Jan2015 17:11, jarod_v6 at libero.it <jarod_v6 at libero.it> wrote:
>I created a class that invoke from another file another class
> I get an error that I do not understand: gobal name Job is not defined
>However If I see the class imported I found the class Job.
>Any suggestion or example on class invoke another class
First, please cut/paste error messages, filenames and code. Do not hand type
them, as that introduces errors.
For example, I suspect you mean "job.py", not "job,py".
>from core.job import *
It is not recommended to import "*". Just impor the names you need. It avoids
_unexpected_ names leaking into your program: you might be using such a name
for something else!
> def __initi__:
> tp = open("/tmp/file.txt")
> def gus(self):
> tr = Job()
Because you have hand typed things I cannot be sure - it may just be a mistake
- but "job.py" defines a class "Jobs". In "trial.py" you use the name "Job".
Not the same!
Cameron Simpson <cs at zip.com.au>
Beware of bugs in the above code; I have only proved it correct, not tried it.
- Donald E. Knuth
More information about the Tutor