Reputation: 11
How To Create Function With Dot in its Name Like:
def Something.FunctionName():
print("Hello World!")
I Did Know How To Do it But I Forgot How To Do That.
Like in LUA:
Something = {}
function Something.TestFunction()
print("Hello World!")
end
Thanks!
Upvotes: 0
Views: 52
Reputation: 11652
Something like:
class Something: PrintHello = staticmethod(lambda: print("Hello World!"))
Something.PrintHello()
Alternative, using types.SimpleNamespace
:
>>> from types import SimpleNamespace
>>> Something = SimpleNamespace(PrintHello=lambda: print('Hello World!'))
>>> Something.PrintHello()
Hello World!
"You can, but don't do"
locals()['Something.FunctionName'] = lambda: print("Hello World!")
locals()['Something.FunctionName']()
Upvotes: 1