The 2to3 tool that ports Python 2 code to Python 3 will recognize this usage and leave the new builtins alone. But that's something that needs looking in to. in this case, while a plain zip = izip may not be. For instance, I'm not 100% sure, but believe that the 2to3 tool will re-write zip correctly as list(zip(. The advantage of using future_builtin is that it's in effect a bit more "explicit" as to intended behaviour of the module, supported by the language syntax, and possibly recognised by tools. You do however then have the same problem of ImportError - so: try:įrom itertools import izip as zip # < 2.5 or 3.x help(zip) If you run the above program, you will get the following results. Loop over two or more sequences at the same time. Run the following code to get the help on zip() function. S1 abc S2 xyz123 print zip (S1, S2) print map (None, S1, S2) 1. The module standardizes a core set of fast, memory efficient tools that are useful by themselves or in. Look at the doc of the zip() function using help method. Each has been recast in a form suitable for Python. Not sure this is really an answer, or I should elaborate on my comment, and in hindsight probably not even a very good comment anyway, but:įirstly, you can just simplify it to: try:įrom 2.6 you can use as per the docs: from future_builtins import map # or zip or filter zip() function is used to group multiple iterators.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |