I was wondering if there is a way to access specific dictionary values within user-defined objects?
E.g.
class Test():
def __init__(self, a, b, c):
self.a=a
self.b=b
self.c=c
test1=Test("text", 0, {"key1":0, "key2":1})
When doing
test1.c
I get:
{'key1': 0, 'key2': 1}
But how can I get the dictionary value of, lets say, "key1" (only "key1")?
Also, I am trying to add the content of an object to a list (as specific list elements). Is that somehow possible?
I am trying to do something like:
test1_list=[]
test1_list=[].append(Test("text", 0, {"key1":0, "key2":1}))
When I do:
print(test1_list)
I only get:
None
instead of:
["text", 0, {"key1":0, "key2":1}]
test1.c['key1']. You should review introductionary material like the Python tutorial.test1object or the content of the fields oftest1?