Support Board
Date/Time: Sat, 23 Nov 2024 17:43:43 +0000
Post From: Python for Sierra Chart
[2022-12-10 20:58:35] |
User719512 - Posts: 262 |
I found 1 bug and 1 nit in the excellent code posted by Kiwi in post #67 (Python for Sierra Chart | Post: 269962). Edge case with a time very close to midnight where the rounding code rounds the value up to 86400 which then causes helper() to use a factor of 1 that causes the hour to come back as 24 (valid range is 0-23). Since the code discards milliseconds, an easy fix is to detect this and coerce the time to 86399 (23:59:59). In deserialize(), change code to: def deserialize(excelDateAndTime): """ Returns excel date time as Python datetime object """ date_tok = int(excelDateAndTime) time_tok = round(86400*(excelDateAndTime - date_tok)) # account for rounding error for excelDateAndTime like 44899.99999549769 if time_tok == 86400: time_tok = 86399 d = date(1899, 12, 30) + timedelta(date_tok) t = time(*helper(time_tok, (24, 60, 60, 1000000))) return datetime.combine(d, t) On Windows, the csv will have extra newlines between each line. A fix to that is to change the open() call to pass a `newline` argument: ftsv = open(fileoutput, 'w', newline='') Thanks again Kiwi for the sample code. Not only did that help with my issue to parse scid files, I learned a bit more about Python as well in an area I had not gained much experience yet. Date Time Of Last Edit: 2022-12-10 23:13:30
|