By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,768 Members | 2,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,768 IT Pros & Developers. It's quick & easy.

what does this mean?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.