Re: [Python-Dev] str.strip() enhancement

2005-09-03 Thread Raymond Hettinger
> > Even if an example or two is found, it is worth complicating the
API.
> > Keep in mind the difficulties that plague str.split() -- that is
what
> > happens when a function grows beyond a single, clear, unified,
> > cohesive
> > concept.
> 
> I am not aware of these difficulties, any pointers?

Yes.  From memory, write-down what you think str.split() does.  Then
look at the docs and see how much you got wrong and how much you missed.
A thorough answer would cover empty string behaviors, the return type,
whether None is allowed, whether a keyword argument is acceptable, and
the effects of using a unicode or UserString argument.  For extra
credit, write down the length invariant and determine whether a
string.join() invariant would always hold.

The str.split() API has led to countless doc revisions, invalid error
reports, newsgroup discussions, and questions on the tutor list.  We
ought to keep it unchanged for Py3.0 just to serve as a warning to
future generations ;-)




>  From an API pow, I do not think it neccessarily complicates it

Please stop smoking crack before posting to python-dev ;-)
Try updating the doc string, library reference entry, and the test
suite.  Be sure to specify that the proposed arguments are
non-commutative and whether general iterables are allowed.  Then report
back that there was no change in complexity.




>, but
> rather generalizes it in a way that may not be very usable :)
> I can understand that it would probably not be worth the effort
> though...

Hmm, that suggests another design principle, "If a proposer lacks faith
in his or her own proposal, it is doomed."



Raymond

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] str.strip() enhancement

2005-09-03 Thread Jonny Reichwald

Raymond Hettinger wrote:

> [Jonny Reichwald]
>> Would this be useful for anyone else besides me?
>
> Probably not.

ok

> Even if an example or two is found, it is worth complicating the API.
> Keep in mind the difficulties that plague str.split() -- that is what
> happens when a function grows beyond a single, clear, unified,  
> cohesive
> concept.

I am not aware of these difficulties, any pointers?
 From an API pow, I do not think it neccessarily complicates it, but  
rather generalizes it in a way that may not be very usable :)
I can understand that it would probably not be worth the effort  
though...


-- 
Jonny Reichwald

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] str.strip() enhancement

2005-09-03 Thread Josiah Carlson

"Raymond Hettinger" <[EMAIL PROTECTED]> wrote:
> 
> [Jonny Reichwald]
> > I would like to suggest a small enhancement to str.strip().
> > By expanding its current form, where it only takes a char list, to
> > taking any list containing either char lists or string lists, it is
> > possible to remove entire words from the stripped string.
>  . . .
> 
> > Would this be useful for anyone else besides me?
> 
> Probably not.

There is also the point that this functionality is a 4-line function...

def trim_endings(strng, endings):
for ending in endings:
if ending and string.endswith(ending):
return strng[:-len(ending)]

 - Josiah

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] str.strip() enhancement

2005-09-03 Thread Raymond Hettinger
[Jonny Reichwald]
> I would like to suggest a small enhancement to str.strip().
> By expanding its current form, where it only takes a char list, to
> taking any list containing either char lists or string lists, it is
> possible to remove entire words from the stripped string.
 . . .

> Would this be useful for anyone else besides me?

Probably not.

Have you seen any other requests for something similar?
Are there precedents in any other language?
Can you point to examples of existing code other than your own that
would benefit?

Even if an example or two is found, it is worth complicating the API.
Keep in mind the difficulties that plague str.split() -- that is what
happens when a function grows beyond a single, clear, unified, cohesive
concept.



Raymond

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com