what does this mean?

M

mr. ice

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
 
P

Peter Otten

mr. ice said:
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.
.... 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
 
M

Mike C. Fletcher

mr. ice said:
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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top