[Python-Dev] Clean way in python to test for None, empty, scalar, and list/ndarray? A prayer to the gods of Python

Terry Reedy tjreedy at udel.edu
Sun Jun 16 05:55:43 CEST 2013


On 6/15/2013 5:45 PM, Tres Seaver wrote:

> Given that strings are implemented in C,

That is a current implementation detail. String functions were 
originally written in python in string.py. Some used 'for c in s:'. The 
functions only because methods after 2.2. I presume Pypy starts from 
Python code again.

 > there is no real "iteration"
> happing (in the Python sense) in their methods.

I disagree, but not relevant.

>  What stdlib code can you
> point to that does iterate over them in Python?  I.e.:
>
>    for c in stringval:

Using Idle's grep (Find in files) for ...Python33/Lib/*.py:
'for c in' 193 hits
'for ch in' 30 hits
'for chr in' 0 hits
'for char in' 14 hits.

Some, especially in the 193, are false positives, but most are not. 
There are at least a few other 'for name in string' uses: for instance, 
'for a in _hexdig for b in _hexdig' where _hexdig is 
'0123456789ABCDEFabcdef'.

-- 
Terry Jan Reedy



More information about the Python-Dev mailing list