473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

% operator -- did Python or C++/boost come first?

Up until recently, Python was the only language I'd ever seen that
used the % operator for string replacement. Today, I was perusing the
C++ Boost libraries, and discoverd that boost::format uses a very
similar syntax. The following lines print the same thing in Python
and C++, respectively.

print "int->%i, string->%s" % (42, "wugga, wugga")
cout << boost::format ("int->%i, string->%s\n") % 42 % "wugga, wugga";

The question is, which came first? Did boost adapt the Python syntax,
or the other way around, or did they both evolve in parallel? I'm not
talking about the use of % in the C/printf style format specifier, but
the use of % as an operator to connect the format specifier with the
data to be formatted.
Jul 19 '05 #1
1 1904
ro*@panix.com (Roy Smith) wrote in message news:<be**********@panix2.panix.com>...
Up until recently, Python was the only language I'd ever seen that
used the % operator for string replacement. Today, I was perusing the
C++ Boost libraries, and discoverd that boost::format uses a very
similar syntax. The following lines print the same thing in Python
and C++, respectively.

print "int->%i, string->%s" % (42, "wugga, wugga")
cout << boost::format ("int->%i, string->%s\n") % 42 % "wugga, wugga";

The question is, which came first? Did boost adapt the Python syntax,
or the other way around, or did they both evolve in parallel? I'm not
talking about the use of % in the C/printf style format specifier, but
the use of % as an operator to connect the format specifier with the
data to be formatted.


If you haven't already, I reccomend reading the design rationale for
any extensions you're interested in (and that have it of course). The
one for format is at http://boost.org/libs/format/doc/choices.html.
Python's use of the same syntax is mentioned, along with many other
reasons for the choice of the operator (and many more for why << is a
bad choice). So it would appear that Python came first.
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roy Smith | last post by:
Up until recently, Python was the only language I'd ever seen that used the % operator for string replacement. Today, I was perusing the C++ Boost libraries, and discoverd that boost::format uses...
13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
16
by: gorda | last post by:
Hello, I am playing around with operator overloading and inheritence, specifically overloading the + operator in the base class and its derived class. The structure is simple: the base class...
9
by: Lonnie Princehouse | last post by:
There doesn't seem to be any way to customize the behavior of "is" as can be done for other operators... why not?
0
by: Pedro | last post by:
Hello pythonians! ;-D , I have a little problem when I expose (assisted by boost.python) classes with virtual functions, specially with operator(). In the C++ code below I test two different...
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
11
by: Osiris | last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file:...
0
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
9
by: Tim H | last post by:
Why is the following code not valid? I mean, I see the code and it doesn't allow it, but I am curious about the rationale? boost::shared_ptr<intpi = new int; pi = new int; Thanks Tim
3
by: Martin T. | last post by:
Hello. I tried to overload the operator<< for implicit printing of wchar_t string on a char stream. Normally using it on a ostream will succeed as std::operator<<<std::char_traits<char> will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.