[Zope-dev] Re: [Zope-Checkins] SVN: Zope/trunk/lib/python/OFS/Traversable.py using startswith()

2006-02-28 Thread Lennart Regebro
On 2/28/06, Andreas Jung [EMAIL PROTECTED] wrote:
 -if name[0] == '_':
 +if name.startswith('_'):

Just a question: Is this only a matter of stylistic changes, or is
there some, like, speedup involved?

--
Lennart Regebro, Nuxeo http://www.nuxeo.com/
CPS Content Management http://www.cps-project.org/
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


[Zope-dev] Re: [Zope-Checkins] SVN: Zope/trunk/lib/python/OFS/Traversable.py using startswith()

2006-02-28 Thread Philipp von Weitershausen
Lennart Regebro wrote:
-if name[0] == '_':
+if name.startswith('_'):
 
 Just a question: Is this only a matter of stylistic changes, or is
 there some, like, speedup involved?

In general, using str.startswith and str.endswith is a failsafe because
''.startswith('_') simply returns False, ''[0] == '_' raises a KeyError.
So, if you really know that your string has at least the length you're
trying to test it against, using the index/slice notation is ok. In all
other cases I would prefer str.startswith and str.endswith.

Philipp
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: [Zope-Checkins] SVN: Zope/trunk/lib/python/OFS/Traversable.py using startswith()

2006-02-28 Thread Andreas Jung



--On 28. Februar 2006 21:41:24 +0100 Philipp von Weitershausen 
[EMAIL PROTECTED] wrote:



Lennart Regebro wrote:

-if name[0] == '_':
+if name.startswith('_'):


Just a question: Is this only a matter of stylistic changes, or is
there some, like, speedup involved?


In general, using str.startswith and str.endswith is a failsafe because
''.startswith('_') simply returns False, ''[0] == '_' raises a KeyError.
So, if you really know that your string has at least the length you're
trying to test it against, using the index/slice notation is ok. In all
other cases I would prefer str.startswith and str.endswith.



But Lennart is right that in this case name should in general never be an
empty string and in addition  startswith() is in this case 100% slower
than using slicing.

-aj




pgpiYM5OXCXJu.pgp
Description: PGP signature
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )


Re: [Zope-dev] Re: [Zope-Checkins] SVN: Zope/trunk/lib/python/OFS/Traversable.py using startswith()

2006-02-28 Thread Lennart Regebro
 But Lennart is right that in this case name should in general never be an
 empty string and in addition  startswith() is in this case 100% slower
 than using slicing.

No, I'm not, Florent is. I just asked. :-)

--
Lennart Regebro, Nuxeo http://www.nuxeo.com/
CPS Content Management http://www.cps-project.org/
___
Zope-Dev maillist  -  Zope-Dev@zope.org
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )