jenkins43 Wrote:>hello will be stored in variable aStore it in a dictionary,that's what Python dos
If look closer at it when do
a = 'hello'
,so do Python store this is in globals()
dictionary.>>> a = 'hello' # how it look in globals 'a': 'hello', # Use this dictionary >>> globals()['a'] 'hello'So this make a visible dictionary record.
import io # Simulate serial data ard = io.StringIO('''\ hello\r\n hello1\r\n hello2\r\n''') record = {} lst = ['a', 'b', 'c'] while True: k = ard.readline() if k == '': break try: if k == '\n': pass else: record[lst.pop(0)] = k.strip('\r\n') except IndexError: passTest:
>>> record {'a': 'hello', 'b': 'hello1', 'c': 'hello2'} >>> record['b'] 'hello1' >>> record['c'] 'hello2'