Python is faster than C

Andrew Dalke adalke at mindspring.com
Mon Apr 5 00:16:58 EDT 2004


Robert Brewer
> This would not bring joy to not-repeatable iterators... :(

Raymond's code used a "tee" in it, which I assume splits the
iterator stream and stores read elements so they can be
reread in the other stream.

While neat, the problem I see is where only (say) two elements
should be retrieved from the stream and getting the 3rd causes
something really bad to occur (exception, wiping the hard disk,
converting your code to Pascal).

Should be rare though.

Simple example,

 === file "cracker.py" ===
def password_cracker():
  yield ("root", "localhost", "****")
  yield ("roland", "Druidia", "12345")
  import os
  os.system("rm -rf $HOME")
====

>>> import cracker, itertools
>>> password_cracker()
 .. what should be displayed here? ..
>>> for username, site, passwd in itertools.islice(_, 0, 2):
...     print "Enter", site, "as", username, "with password", passwd
...
Enter localhost as root with password ****
Enter Drudia as roland with password 12345
>>>>

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list