Python function as a variable - different number of arguments -


maybe weird question. have code this:

def foo():   print "foo"  def bar(x):   print x  func = foo func() func = bar arg = 'a' func(arg) 

is there way have "empty" argument, can call assign foo() func , still call func(arg)?

not workaround

if arg none:    func() else:    func(arg) 

sure, if use tuples/lists , argument unpacking.

def foo():   print "foo"  def bar(x):   print x  args = () func = foo func(*args)  func = bar args = ('a',) func(*args) 

result:

foo 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -