Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > what does this mean?

Reply
Thread Tools

what does this mean?

 
 
mr. ice
Guest
Posts: n/a
 
      05-19-2004
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
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      05-19-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

 
Reply With Quote
 
 
 
 
Mike C. Fletcher
Guest
Posts: n/a
 
      05-19-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 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/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET 2.0 ASPx Page does not load, but HTM does prabhupr@hotmail.com ASP .Net 1 02-08-2006 12:57 PM
Button OnClick does not fire on first postback, but does on second Janet Collins ASP .Net 0 01-13-2006 10:08 PM
Does the 2.0 Framework come out when Visual Studio .NET 2005 does? needin4mation@gmail.com ASP .Net 3 10-07-2005 12:55 AM
CS0234 Global does not exist ... but it genuinely does Bill Johnson ASP .Net 0 07-08-2005 06:34 PM
Does no one else think microsoft does a poor job? =?Utf-8?B?SmVyZW15IEx1bmRncmVu?= Wireless Networking 2 11-20-2004 12:17 AM



Advertisments