Python Forum
Python Error (Traceback & ValueError) Help!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Error (Traceback & ValueError) Help!
#1
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()
Reply
#2
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
Reply
#3
(Dec-19-2016, 02:19 AM)Larz60+ Wrote: 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

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!
Reply
#4
Please post the entire traceback, it contains valuable information
that shows the context of the error.
please show print result
Reply
#5
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.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Traceback Error mg24 2 2,053 Nov-21-2022, 02:35 PM
Last Post: snippsat
Star python exception handling handling .... with traceback mg24 3 4,362 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Strange error ValueError: dimension mismatch Anldra12 0 3,109 Aug-17-2021, 07:54 AM
Last Post: Anldra12
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 6,144 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  Python ValueError The value of a Series is abmbiguous nhl66pens 2 3,517 Oct-17-2020, 02:46 PM
Last Post: jefsummers
  Error When Plotting ValueError: x and y must have same first dimension JoeDainton123 1 11,070 Oct-04-2020, 12:58 PM
Last Post: scidam
  Receiving ValueError("bad input shape {0}".format(shape)) error SuryaCitizen 2 4,861 Jun-01-2020, 06:45 AM
Last Post: pyzyx3qwerty
  getting error ValueError: time data '' does not match format '%H:%M' srisrinu 2 7,156 Apr-09-2020, 11:12 AM
Last Post: srisrinu
  Traceback error in PyCharm but not in other IDEs? devansing 7 10,075 Mar-05-2020, 11:27 AM
Last Post: buran
  Nameparser - Traceback error tjnichols 2 3,626 Feb-28-2020, 05:11 PM
Last Post: GodMaster

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.