Aug-12-2020, 10:34 PM
(Aug-12-2020, 03:16 PM)mandaxyz Wrote: The terms say that I come back if I find the solution. I use 'exec' to create a variable from string.Yes,but a better way could be to use a data structure like dictionary.
What's really happens when do
exec("abc=123")
or just abc = 123
,is that Python map this to a internal global
dictionary.>>> exec("abc = 123") >>> globals()['abc'] 123 >>> type(globals()) <class 'dict'>So the way to make this more clear is to use real visible dictionary.
>>> d = dict(abc=123, foo=456) >>> d {'abc': 123, 'foo': 456} >>> d['abc'] 123 # Then also get method like get >>> d.get('abc', 'Not in record') 123 >>> d.get('abcd', 'Not in record') 'Not in record' >>> d.get('foo', 'Not in record') 456
mandaxyz Wrote:Bye, I will make effort next time, I will try to be perfectTo be perfect is a goal we all will fail at
I think just a little expatiation of the goal of doing this was the point here.