Re: NameError when generating Python code

"R. Tyler Ballance" <[email protected]>
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
On Thu, Apr 16, 2009 at 06:17:51PM +0100, Martin Skøtt wrote:
>    Hi,
> 
>    I'm trying to use Cheetah 2.1.0.1 to generate some Python stub classes,
>    but I have encountered a problem which to me looks like Cheetah is
>    actually evaluating the code I generate. Here is the error I get: (Python
>    2.6 on Win XP):
>    Traceback (most recent call last):
>      File "stubGen.py", line 64, in <module>
>        print(t)
>      File "C:\Python26\Lib\site-
>    packages\Cheetah\Template.py", line 982, in __str__
>        def __str__(self): return getattr(self, mainMethName)()
>      File "_HOME_Generator_src_templates_class_tmpl.py", line 89, in respond
>    NameError: global name 'BaseClass' is not defined
> 
>    Here is the template I'm using:
>    from BaseClass import BaseClass
>    class $module.module(BaseClass):
>        pass
> 
>    If I comment out (##) the two first lines it works fine. Any suggestions
>    on how to solve this?

For the list's benefit, this was not an error in recent releases of
Cheetah, but in fact a problem with the syntax of Martin's calls

The template markup:
	class $module.module(BaseClass)

Was resulting in the NameMapper trying to call $module.module with the
argument 'BaseClass'.

The correct way to write the code above would be to:

	class ${module.module}(BaseClass) 

To avoid the NameMapper getting mixed up with what you're trying to do


Cheers
-- 
-R. Tyler Ballance
Slide, Inc.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)

iEYEARECAAYFAknn3foACgkQFCbH3D9R4W+fjQCeK+GWcaJ8YbzMY7bGsZieP1SK
KkYAn3TlsMuURyfrdglG0guPqBcGs1dk
=bL+l
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.