gah! I hate the new string syntax

Amit Patel amitp at Xenon.Stanford.EDU
Sun Mar 4 07:45:40 CET 2001

 Russell E. Owen <owen at astrono.junkwashington.emu> wrote:
| In article <mailman.983485923.1136.python-list at>,
|  "Sean 'Shaleh' Perry" <shaleh at> wrote:
| >return ";".join(["%s=%s" % (k, params[k]) for k in params.keys()])
| >
| >every day python seems to be moving closer to the line noise aspect of
| >coding.
| >
| Mostly I think string methods are a great idea. One thing that annoyed 
| me about python early on was the plethora of global functions that made 
| more sense to me (a smalltalk lover, I admit) as methods. So overall I'm 
| very pleased to see the new string methods.
| However, I do agree that join is not intuitive. I believe the problem 
| (at least for the way I look at it) is that join should be a list 
| method, not a string method. I.e.:
|   joined_string = ['a', 'b'].join(', ')
| makes a lot of sense to me. The current join string method does not.

One thing that I *liked* about Python was that it had a split(a,b)
function instead of a method:  a.split(b) or b.split(a).

When I see split(a,b), I think, "Oh, this isn't an inherent part of a
string-- *I* could write it, even though I didn't write the string

When I see b.split(a), I think, "This is a basic part of a string, and
I *cannot* write it."

If I have a split-like function I'd like to write (perhaps
re.split, or some custom split function), then what I'll see is:

          function style              method style

          string.split(a,b)           b.split(a)
          re.split(a,b)               re.split(a,b)
          mysplit(a,b)                mysplit(a,b)

Note that with the function style, they're consistent -- MY function
is on equal footing with string.split.  But with the new method style,
the split method on strings is elevated to a privileged position that
I cannot do for mysplit.  So now I have inconsistent syntax.

So I will continue to use string.split in my code.  I'll only use the
methods for things that are conceptually inherently tied to strings.
*Maybe* replace and index.  But certainly not capitalize or center.
They feel like a user definable function that are in the string module
for convenience.  At least in my mind, capitalize is NOT part of the
basic functionality of a string class.

      - Amit
Amit J Patel, Computer Science Department, Stanford University

More information about the Python-list mailing list