I am new to Python and I wanted to input a dictionary through command line and have below code print the key:
for line in sys.stdin:
adict ={}
line = line.strip()
adict = line
for key, value in adict.items():
print(key)
I keep getting the error: AttributeError: 'str' object has no attribute 'items'.
When I try to create a dictionary and print it, it does:
data = {}
data[str(0) + str(1)] = "A " + str(0) + " " + str(1.0)
for key, value in data.items():
print(key)
Why am I not able to enter a dictionary from the command line and have the key printed? I am taking the dictionary input ({'01': 'A 0 1.0'}) and storing it in a dictionary variable, adict. adict prints correctly but why can't I use items() on it? Am I doing something incorrectly?