I'm writing a very simple python program to read in an ascii csv file with multiple records formatted like this:
"2010.3.13, 0.0.0, 10.1, 12.2, 9.9, 10.1, 2500" # i.e. a list of daily stock prices with date,time,open, high,low,close, volume fields
I use this python code to read each line from the ascii file named f:
for line in f: d,t,o,h,l,c,v = line.split(',') # where d stands for date, etc
Much to my pleasant shock, the ascii string "2010.3.13" ends up as a datetime.date object stored in the variable 'd'.
So, how did this pleasant surprise happen? Why isn't that string stored in 'd' as the string "2010.3.13" instead of as a date object?
Python must be sneaking around behind my back doing automagical type conversions, but how/where is it happening?
Thanks!
BTW, I did "import datetime" because I was planning to do all the ugly date conversions myself. That's why I'm pleasantly surprised.
"2010.3.13, 0.0.0, 10.1, 12.2, 9.9, 10.1, 2500" # i.e. a list of daily stock prices with date,time,open, high,low,close, volume fields
I use this python code to read each line from the ascii file named f:
for line in f: d,t,o,h,l,c,v = line.split(',') # where d stands for date, etc
Much to my pleasant shock, the ascii string "2010.3.13" ends up as a datetime.date object stored in the variable 'd'.
So, how did this pleasant surprise happen? Why isn't that string stored in 'd' as the string "2010.3.13" instead of as a date object?
Python must be sneaking around behind my back doing automagical type conversions, but how/where is it happening?
Thanks!
BTW, I did "import datetime" because I was planning to do all the ugly date conversions myself. That's why I'm pleasantly surprised.
Comment