Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42440 > unrolled thread
| Started by | iMath <redstone-cold@163.com> |
|---|---|
| First post | 2013-03-31 21:45 -0700 |
| Last post | 2013-04-02 19:34 -0700 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.python
executor.map() TypeError: zip argument #2 must support iteration iMath <redstone-cold@163.com> - 2013-03-31 21:45 -0700
Re: executor.map() TypeError: zip argument #2 must support iteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-01 07:48 +0000
Re: executor.map() TypeError: zip argument #2 must support iteration iMath <redstone-cold@163.com> - 2013-04-02 19:34 -0700
| From | iMath <redstone-cold@163.com> |
|---|---|
| Date | 2013-03-31 21:45 -0700 |
| Subject | executor.map() TypeError: zip argument #2 must support iteration |
| Message-ID | <29b241a1-44ce-45a0-81b6-429245931c05@googlegroups.com> |
executor.map() TypeError: zip argument #2 must support iteration
when I run it ,just generated TypeError: zip argument #2 must support iteration.
can anyone help me fix this problem ?
import time, concurrent.futures
lst100=[i for i in range(100)]
t1=time.clock()
print(list(map(str,lst100)))
t2=time.clock()
print(t2-t1)
t3=time.clock()
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor:
future_to_url = executor.map(str,lst100, 60)
print(list(future_to_url))
t4=time.clock()
print(t4-t3)
[toc] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-04-01 07:48 +0000 |
| Message-ID | <51593bd2$0$29967$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #42440 |
On Sun, 31 Mar 2013 21:45:21 -0700, iMath wrote:
> executor.map() TypeError: zip argument #2 must support iteration
>
> when I run it ,just generated TypeError: zip argument #2 must support
> iteration. can anyone help me fix this problem ?
Yes. Read the error message, and inspect the line that is in error. You
have:
> future_to_url = executor.map(str,lst100, 60)
executor.map has three arguments:
Arg 0: str
Arg 1: list of 100 ints
Arg 2: int 60
Argument 2, the number 60, does not support iteration, since it is an int.
Now read the docs for map. At the interactive interpreter, do this:
py> from concurrent.futures import ThreadPoolExecutor
py> help(ThreadPoolExecutor.map)
and you will see the following documentation:
map(self, fn, *iterables, timeout=None)
Returns a iterator equivalent to map(fn, iter).
Args:
fn: A callable that will take take as many arguments as there are
passed iterables.
timeout: The maximum number of seconds to wait. If None, then
there is no limit on the wait time.
Notice that the iterables argument is prefixed with * symbol. That means
that it collects all the remaining positional arguments, which means that
the timeout argument is keyword only.
So try this:
future_to_url = executor.map(str, lst100, timeout=60)
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | iMath <redstone-cold@163.com> |
|---|---|
| Date | 2013-04-02 19:34 -0700 |
| Message-ID | <f02fb4c3-944e-4a1f-8803-987f319fbabf@googlegroups.com> |
| In reply to | #42448 |
在 2013年4月1日星期一UTC+8下午3时48分34秒,Steven D'Aprano写道: > On Sun, 31 Mar 2013 21:45:21 -0700, iMath wrote: > > > > > executor.map() TypeError: zip argument #2 must support iteration > > > > > > when I run it ,just generated TypeError: zip argument #2 must support > > > iteration. can anyone help me fix this problem ? > > > > Yes. Read the error message, and inspect the line that is in error. You > > have: > > > > > future_to_url = executor.map(str,lst100, 60) > > > > executor.map has three arguments: > > > > Arg 0: str > > Arg 1: list of 100 ints > > Arg 2: int 60 > > > > Argument 2, the number 60, does not support iteration, since it is an int. > > > > Now read the docs for map. At the interactive interpreter, do this: > > > > py> from concurrent.futures import ThreadPoolExecutor > > py> help(ThreadPoolExecutor.map) > > > > > > and you will see the following documentation: > > > > map(self, fn, *iterables, timeout=None) > > Returns a iterator equivalent to map(fn, iter). > > > > Args: > > fn: A callable that will take take as many arguments as there are > > passed iterables. > > timeout: The maximum number of seconds to wait. If None, then > > there is no limit on the wait time. > > > > > > Notice that the iterables argument is prefixed with * symbol. That means > > that it collects all the remaining positional arguments, which means that > > the timeout argument is keyword only. > > > > So try this: > > > > > > future_to_url = executor.map(str, lst100, timeout=60) > > > > > > -- > > Steven thanks for clarification.I thought argument 2 is lst100
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web