Coming from other scripting languages like AutoHotkey and PowerShell, it seems verbose to have to declare a class in order to return an object from a function. Is there a simpler way to accomplish this in Python?
def structuring_element():
return {kind: 'flat'; structure: []}
tool = structuring_element()
print(tool.kind)
# 'flat'
print(tool.structure)
# []
Looks like the simplest way is to declare a class and create the structuring element in the __init__
statement like so:
class structuring_element(object):
def __init__(self):
self.kind = 'flat'
self.structure = []
Currently I'm using multiple outputs but it doesn't feel as elegant as being able to keep them in an object together:
def structuring_element():
return 'flat', []
kind, structure = structuring_element()