interating over single element array

Terry Reedy tjreedy at udel.edu
Sat Jun 9 13:12:42 EDT 2007


"Basilisk96" <basilisk96 at gmail.com> wrote in message 
news:1181391368.112303.284890 at q75g2000hsh.googlegroups.com...
| "Terry Reedy" <tjre... at udel.edu> wrote:
| > Any what if 'filelist' is any iterable other than a string or list? 
Your
| > code is broken, and unnecessarily so.  So I would call the parameter
| > 'files' and test for isinstance(files, str) #or basestring.  And wrap 
if it
| > is.
|
| Can you give an example of such an iterable (other than a tuple)?

Tuple was the first thing I thought of, and one will break the list test. 
The next would be an iterator that walks a file hierarchy spitting out the 
names of non-directory files, or all files with a certain extension, or all 
files with a certain owner, or timestamp characteristic.

| I'd certainly like to fix my 'fix' to work for a more general case.

As I said, I think it as simple as changing 'not list' to 'is string'.

tjr







More information about the Python-list mailing list