Re: Question about lambda and variable bindings

2008-03-01 Thread poof65
An idea, i don't know if it will work in your case.

for x in xrange(10):
  funcs.append(lambda p,z=x: testfunc(z+2,p))

On Sun, Mar 2, 2008 at 3:50 AM, Michael Torrie <[EMAIL PROTECTED]> wrote:
> I need to use a lambda expression to bind some extra contextual data
>  (should be constant after it's computed) to a call to a function.  I had
>  originally thought I could use something like this demo (but useless) code:
>
>  funcs=[]
>
>  def testfunc(a,b):
> print "%d, %d" % (a,b)
>
>  for x in xrange(10):
> funcs.append(lambda p: testfunc(x+2,p))
>
>
>  Now what I'd like is to call, for example, funcs[0](4) and it should
>  print out "2,4".  In other words I'd like the value of x+2 be encoded
>  into the lambda somehow, for funcs[x].  However the disassembly shows
>  this, which is reasonable, but not what I need:
>
>  >>> dis.dis(funcs[0])
>   2   0 LOAD_GLOBAL  0 (testfunc)
>   3 LOAD_GLOBAL  1 (x)
>   6 LOAD_CONST   0 (2)
>   9 BINARY_ADD
>  10 LOAD_FAST0 (p)
>  13 CALL_FUNCTION2
>  16 RETURN_VALUE
>
>  The LOAD_GLOBAL 1 (x) line is definitely a problem.  For one it refers
>  to a variable that won't be in scope, should this lambda be called from
>  some stack frame not descended from the one where I defined it.
>
>  So how can I create a lambda expression that calculates a constant based
>  on an expression, rather than referring to the object itself?  Can it be
>  done?
>
>  Michael
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parralel downloads

2008-03-08 Thread poof65
For your problem you have to use threads.

You can have more information here.
http://artfulcode.nfshost.com/files/multi-threading-in-python.html


On Sat, Mar 8, 2008 at 1:11 PM, John Deas <[EMAIL PROTECTED]> wrote:
> Hi,
>
>  I would like to write a python script that will download a list of
>  files (mainly mp3s) from Internet. For this, I thought to use urllib,
>  with
>
>  urlopen("myUrl").read() and then writing the resulting string to a
>  file
>
>  my problem is that I would like to download several files at the time.
>  As I have not much experience in programming, could you point me the
>  easier ways to do this in python ?
>
>  Thanks,
>
>  JD
>  --
>  http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list