Last active
August 31, 2018 10:53
-
-
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 :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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