I try to edit and find data from a text file with python 2.7 (data from stock market)
alon.najman at gmail.com
alon.najman at gmail.com
Fri Sep 7 07:52:46 EDT 2018
hi,
I try to edit a text file with python 2.7:
***** AAPL *****
Date: September 07 2018
Time: 14:10:52
Price: ,068,407
Ask: None
High: None
Low: None
Previous Close: ,068,407
Volume: $ 227.35 / $ 221.30
Market Cap: 20.23
but when I write it to a file I get:
{'previous_close': ',068,407', 'volume': u'$\xa0227.35\xa0/\xa0$\xa0221.30', 'market_cap': '20.23', 'price': ',068,407', 'high': 'None', 'ask': 'None', 'low': 'None', 'time': '14:15:45', 'date': 'September 07 2018', 'ticker': 'AAPL'}
why is that? and how do I get the price value only? so I will have only that in a variable? for example the variable: Price.
this is my code..
import csv
import itertools
from nasdaq_stock import nasdaq_stock
x=str(nasdaq_stock.stock('AAPL'))
with open("log.txt", "w") as text_file:
text_file.write(format(x))
with open('log.txt', 'r') as in_file:
lines = in_file.read().splitlines()
stripped = [line.replace(","," ").split() for line in lines]
grouped = itertools.izip(*[stripped]*1)
with open('log.csv', 'w') as out_file:
writer = csv.writer(out_file)
writer.writerow(('title', 'intro', 'tagline'))
for group in grouped:
writer.writerows(group)
#locate cell
import csv
def read_cell(x, y):
with open('log.csv', 'r') as f:
reader = csv.reader(f)
y_count = 0
for n in reader:
if y_count == y:
cell = n[x]
return cell
y_count += 1
#I try to find the value of Price..
print (read_cell(2,3))
More information about the Python-list
mailing list