The correct way to bind function?

Viewed 15

I use a python package which has a function should bind function(function name/address).
I create a config file and want to bind lots of functions in a loop. But find a problem like this:

def cus_print(func):
    func()


def main():
    a = []
    for i in range(2):
        a.append(lambda: print(i))

    for each in a:
        cus_print(each)

if __name__ == '__main__':
    main()

result

1
1

The easy way to solve problem?

0 Answers
Related