[Tutor] declare a variable inside a class

Martin A. Brown martin at linux-ip.net
Thu Feb 11 18:23:48 EST 2016

>Thanks for the reply Martin, and in this instance I cannot post the 
>actual code (company rules).

That's often the case.  I think most of us understand that you may 
not be able to post the original code.

>What I can do is say that with the xslt variable defined within the 
>formatter method, everything works, but when I pull it out and put 
>it in the upper level of the class, it gives me a traceback that 
>says the global variable xslt is not defined. Does that help?

I understand what you are saying, but cannot make a more specific 
suggestion, beyond the example I posted before, which included the 
most common reason that people have that problem when moving names 
out of a method into the enclosing class.

Summary: 'xslt' is not in the namespace you think it is in.

I (or others) may be able to help if you use a short, self-contained 
correct example of your problem.  You can change all of the variable 
names.  You can (and should) omit everything that is irrelevant.

When I'm trying to solve a problem like this, I usually crack open 
an editor and try to reproduce the problem in as few lines of code 
as I can.  This often helps me to see my own errors.

Good luck,


Martin A. Brown

More information about the Tutor mailing list