Python Error (Traceback & ValueError) Help! - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python Error (Traceback & ValueError) Help! (/thread-1261.html) |
Python Error (Traceback & ValueError) Help! - helpplease - Dec-19-2016 Anyone here able to help with some python error messages? 1. Traceback (most recent call last): 2. ValueError: time data '' does not match format '%Y%m%d' The code seems to run & execute based on the conditions stated below, up till printing 'we are complete. here is total profit:'. PLEASE HELP! this is the code I'm using: import time from datetime import datetime from time import mktime def backTest(): stance = 'none' buyPrice = 0 sellPrice = 0 previousPrice = 0 totalProfit = 0 bigDataFile = open('AAPL.txt','r') readFile = bigDataFile.read() lineSplit = readFile.split('\n') for everyLine in lineSplit: dividedLine = everyLine.split(',') initialDate = dividedLine[0] unixStamp = mktime(datetime.strptime(initialDate, '%Y%m%d').timetuple()) dateStamp = time.strftime('%d/%m/%Y',time.localtime(unixStamp)) stockPrice = float(dividedLine[4]) reformatted = unixStamp,dateStamp,stockPrice if stance == 'none': if stockPrice < previousPrice: print 'buy triggered!' buyPrice = stockPrice print 'bought stock for',buyPrice stance = 'holding' elif stance == 'holding': if stockPrice > buyPrice * .002 + buyPrice: print 'sell triggered!' sellPrice = stockPrice print 'finished trade, sold for:',sellPrice stance = 'none' tradeProfit = sellPrice - buyPrice totalProfit += tradeProfit print totalProfit previousPrice = stockPrice print 'we are complete. here is total profit:' print totalProfit time.sleep(555) backTest() RE: Python Error (Traceback & ValueError) Help! - Larz60+ - Dec-19-2016 In the future, please use code tags (I added them this time) I'm thinking that dividedLine[0] is not a timestamp. try printing the contents before the conversion RE: Python Error (Traceback & ValueError) Help! - helpplease - Dec-19-2016 (Dec-19-2016, 02:19 AM)Larz60+ Wrote: In the future, please use code tags (I added them this time) My apologies. I am new to this. Thanks for your help! It does print & initialDate is a timestamp. Would you be able to explain, in words, what the two error messages actually mean & how I am to interpret them? Maybe, that way, I could troubleshoot it myself? Thanks! RE: Python Error (Traceback & ValueError) Help! - Larz60+ - Dec-19-2016 Please post the entire traceback, it contains valuable information that shows the context of the error. please show print result RE: Python Error (Traceback & ValueError) Help! - Ofnuts - Dec-19-2016 Traceback is followed by "the stack" (ie, the state of nested function calls...). One end of the stack is where your code has crashed (which is why providing the whole traceback when you ask for help is a good idea). The "ValueError" is an usual answer in Python to an invalid argument in a function call. Given the message it is likely the strptime() call telling you that it cannot parse its input with the format you provided. |