469,949 Members | 2,244 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,949 developers. It's quick & easy.

what does this mean?

I am new to python, The following statement is in the beginning of
class definition in a python scripts, what does it mean? Help?
class %(class_)s_W : public XMsg_W
{
icemon
Jul 18 '05 #1
2 2505
mr. ice wrote:
I am new to python, The following statement is in the beginning of
class definition in a python scripts, what does it mean? Help?
class %(class_)s_W : public XMsg_W
{


You are probably inside a string (if they start with """ or ''' they can go
over multiple lines in python). The script seems to be meant to generate
C++ source code.
print """

.... class %(class_)s_W : public XMsg_W
.... { // more C++ code
.... }
.... """ % {"class_": "MyFancyClass"}

class MyFancyClass_W : public XMsg_W
{ // more C++ code
}

See how the "%(class_)s" thingy was replaced by the value "MyFancyClass"
corresponding to the key "class_" in the dictionary? That's one way to use
the % operator with strings.

Peter

Jul 18 '05 #2
mr. ice wrote:
I am new to python, The following statement is in the beginning of
class definition in a python scripts, what does it mean? Help?
class %(class_)s_W : public XMsg_W
{


You will likely notice that there are "" or '' marks around the text
you're reading there. It looks a lot like a string template that
someone is using to create C++ code. A string like this "Hello
%(name)s_xyz" gets expanded in Python like so:

name = 'this'
value = "Hello %(name)s_xyz" % locals()

yielding:

value == "Hello this_xyz"

So whoever coded the module is likely trying to auto-generate some C++
code using Python string substitution.

HTH,
Mike
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://members.rogers.com/mcfletch/
blog: http://zope.vex.net/~mcfletch/plumbing/
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jukka K. Korpela | last post: by
86 posts views Thread by Michael Kalina | last post: by
2 posts views Thread by Steve Richter | last post: by
121 posts views Thread by typingcat | last post: by
51 posts views Thread by jacob navia | last post: by
1 post views Thread by Frank Rizzo | last post: by
13 posts views Thread by Jason Huang | last post: by
9 posts views Thread by JoeC | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.