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

Evan eed132 at psu.edu
Tue Jul 15 00:46:15 EDT 2003


roy at panix.com (Roy Smith) wrote in message news:<bev3p6$h4l$1 at 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.




More information about the Python-list mailing list