Brython - Python in the browser

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Dec 22 06:05:05 EST 2012


On Sat, 22 Dec 2012 20:08:25 +1100, Chris Angelico wrote:

> I don't see "string % tuple" as a good syntax; I prefer to spell it
> sprintf("format",arg,arg,arg). 

Very possibly one of the worst names ever from a language that excels at 
bad names. "Sprint f"? WTF?

Certainly not appropriate for Python, where a sprintf equivalent would 
return a new string, rather than automatically print the result. Oh 
wait... C's sprintf doesn't automatically print either.

*wink*



> When it
> comes to operators on strings, what I'd prefer to see is something that
> does more-or-less what the operator does with integers - for instance:
> 
> "This is a string" / " " ==> ["This","is","a","string"]

I don't see the connection between the above and numeric division. If it 
were this:

"This is a string" / 3 ==> ["This ", "is a ", "strin", "g"]

(and presumably // 3 would be the same except the "g" would be dropped) 
then I could see the connection. But there's no relationship between 
numeric division, which divides a number up into N equal-sized parts, and 
string splitting as you show above.

Of course, if we can just invent a meaning for the % operator that has 
nothing to do with either percentages or numeric modulo, then we could 
equally invent a meaning for / for strings. But if we did so, it still 
wouldn't have anything to do with numeric division.


> Taking a string modulo a tuple doesn't make any sense in itself, 

Taking an integer cross an integer doesn't make any sense if you haven't 
learned the meaning of the + operator. Why insist that only string 
operators must make inherent sense to somebody who doesn't know what the 
operator means? If we're allowed to learn the meaning of + * and &, why 
not % as well?


-- 
Steven



More information about the Python-list mailing list