[Python-3000] String formating operations in python 3k

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Apr 5 01:44:23 CEST 2006


Barry Warsaw wrote:
> On Tue, 2006-04-04 at 14:28 +1200, Greg Ewing wrote:
> 
>>I'm also not all that keen on $, either inside
>>or outside the string. It seems to me that
>>something like
>>
>>   "User {user} has printed {n} pages"
>>
>>sets off the parameters from the rest of the
>>string more readably than
>>
>>   "User $user has printed $n pages"
> 
> 
> Here i disagree.  $-strings are so familiar to people coming from other
> languages that they instantly "get it".

I'm more interested in long-term readability
and maintainability than in pandering to one-off
impressions when coming from another language.

I don't believe they would have any difficulty
"getting" this, anyway. Can you honestly say
that if you saw something like

   subst("User {user} has printed {n} pages",
     user = user_code, n = page_count)

you wouldn't instantly figure out what was
going on?

There are other problems with the $ syntax too.
The lack of an explicit closing marker causes
problems when the parameter is immediately
followed in the string by an alphanumeric
character. You end up having to allow some
kind of bracketing as an optional extra
anyway, such as

   subst("I'm a ${what}spotter", what = "train")

Seems to me it's simpler as well as clearer
to just make the syntax fully bracketed in the
first place.

--
Greg


More information about the Python-3000 mailing list