I have a weird problem, as I am trying to generate a list of dictionaries to pass them as a parameter to a function. Designing the input "by hand" looks like this:
params = [# Amazon{'q': "AMZN",'x': "NASDAQ",},{'q': "PIH",'x': "NASDAQ",},{'q': "AIR",'x': "NYSE",},{'q': "FCO",'x': "NYSEAMERICAN",},{'q': "7201",'x': "TYO",}
].
I have tried to generate a similar list of dictionaries from a txt file containing a list of tickers (one per line) with the following code:
info = {}
params = []
with open('Test_Tickers.txt') as f:for line in f:info['q'] = line.rstrip()info['x'] = "NYSE"params.append(info)print(info)
The frustrating part is that while the print(info) returns the correct dictionaries
{'q': 'ABB', 'x': 'NYSE'}
{'q': 'ABBV', 'x': 'NYSE'}
{'q': 'ABC', 'x': 'NYSE'}
{'q': 'ABEV', 'x': 'NYSE'}
...
{'q': 'IJS', 'x': 'NYSE'}
the params looks like this:
[{'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, {'q': 'IJS', 'x': 'NYSE'}, ... ]
How can I corrent the code so that the dictionaries contain all the tickers and not only the last one?