tags:

views:

58

answers:

4
def c(*x,**y):
    print x,y
def a(*x,**y):
    print x
    def b(*x1,**y1):
        c(*(x+x1),**dict(y,**y1))
    b()

a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error

thanks

+1  A: 

Replace b() with return b

Running this in Python 3.1:

def c(*x,**y):
    print(x,y)
def a(*x,**y):
    print(x)
    def b(*x1,**y1):
        c(*(x+x1),**dict(y,**y1))
    return b

a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')

produces:

>>> ================================ RESTART ================================
>>> 
(1, 2, 3)
(1, 2, 3, 4, 5, 6) {'a': 1, 'c': '222', 'b': 2, 'd': 'aaa'}
>>> 
Hamish Grubijan
Yeah, Python doesn't automatically return the last line of the function.
Skilldrick
And even if it did, returning b() wouldn't work because that would return the return value of b (None).
Skilldrick
+2  A: 

function a() is not returning a function; actually, it returns None. Therefore, the second set of parenthesis is a call on None object - and that's an error.
Did you intend to return a function, like doing something like return b?

Roberto Liffredo
+1  A: 
a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')#error

I assume you got "object is not callable" exception..

May be you need to return a function object 'b' (not result of the 'b') ?

So instead of

b()

try

return b # without braces and with 'return'
Pydev UA
+1  A: 

The error I get is:

Traceback (most recent call last):
File "./tmp.py", line 11, in a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa') TypeError: 'NoneType' object is not callable

I can fix this by changing your code to:

#!/usr/bin/python

def c(*x,**y):
    print x,y
def a(*x,**y):
    print x
    def b(*x1,**y1):
        c(*(x+x1),**dict(y,**y1))
    return b

a(1,2,3,a=1,b=2)(4,5,6,c='222',d='aaa')

This produces the output:

(1, 2, 3)

(1, 2, 3, 4, 5, 6) {'a': 1, 'c': '222', 'b': 2, 'd': 'aaa'}

You haven't stated what you're trying to achieve though, so I don't know whether or not this is what you want.

James Polley