what does this mean?

Peter Otten __peter__ at web.de
Wed May 19 13:09:33 EDT 2004


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




More information about the Python-list mailing list