Skip to content

Instantly share code, notes, and snippets.

@EmilStenstrom
Last active August 31, 2018 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EmilStenstrom/32cb03232fbd57452e222f8bd2130f08 to your computer and use it in GitHub Desktop.
Save EmilStenstrom/32cb03232fbd57452e222f8bd2130f08 to your computer and use it in GitHub Desktop.
Code found in a library I was considering using... NEVER write code like this :)
class Object:
attributes = ["myattr",
"anotherattr",
"attr1",
"someattr",
"attr5"]
code = "def __init__(self"
for att in attributes:
code = code + ", " + att + " = None"
code = code + "):\n"
for att in attributes:
code = code + " self." + att + "=" + att + "\n"
exec(code)
def toStr(self):
res = "("
for att in Object.attributes:
boo = eval("isinstance(self. " + att + ", str)")
if not boo:
res = res + str(eval("self." + att))
else:
res = res + "\"" + str(eval("self." + att)) + "\""
if att != Object.attributes[len(Object.attributes) - 1]:
res = res + ","
res += ")"
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment