Syntax Suggestion: Pass Function Definition as Argument

David Raymond David.Raymond at tomtom.com
Thu Nov 7 13:04:06 EST 2019


Here is it rewritten using the proposal:
```
    #Definition
    def myFoo (str1, str2, foo, str = " "):
        print( foo(str = str1), foo(str = str2) )


    #Call
    myFoo ("hello", "world!"):
        str = list(str)[0].upper() + str[1:]
        return str
```

Are you looking for multi-line lambdas?
Isn't this basically just defining a function... but without an argument list? How would that know what "str" is?

Since you can already define functions inside of functions, what functionality does this give you that you can't already do with something like this:

def myFoo(str1, str2, foo):
    print(foo(str1), foo(str2))

def main():
    print("Stuff here")
    
    def f1(str):
        str = list(str)[0].upper() + str[1:]
        return str
    myFoo("hello", "world", f1)
    
    def f1(str): #yup, same name
        str = str[:-1] + list(str)[-1].upper()
        return str
    myFoo("hello", "world", f1)
    
    del f1
    
    print("More stuff")

main()


Which results in:
Stuff here
Hello World
hellO worlD
More stuff



More information about the Python-list mailing list