Why the blank lines in output? - 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: Why the blank lines in output? (/thread-37579.html) |
Why the blank lines in output? - Mark17 - Jun-27-2022 I'm having problems with my program so I added a tracer (?) line to print out some variables at the beginning of every iteration [loop]: if current_date != current_date_prev: #debug print(f'current_date is {current_date}, common date is {datetime.utcfromtimestamp(current_date*86400).strftime("%Y-%m-%d")}, trade status is {trade_status}, and control flag is {control_flag}.') current_date_prev = current_dateHere's a segment of the output: Periodically, I get blank lines as seen after current_date 14698. Do you have any idea why that might be the case? The task should be as repetitive as it looks. I get roughly 3500 of these tracer lines total (from 2007 through 2021).In case it matters, I'm using Jupyter Notebook for this. RE: Why the blank lines in output? - Mark17 - Jun-27-2022 In case the trace was close in length to overfilling one line such that if multiple variable fields are close to maximal length then it might push the output to a second line causing the blank line, I retried by adding nine more characters to the end of each line: print(f'current_date is {current_date}, common date is {datetime.utcfromtimestamp(current_date*86400).strftime("%Y-%m-%d")}, trade status is {trade_status}, and control flag is {control_flag}123456789.')I got the same result: only the occasionally blank line interspersed among the output. RE: Why the blank lines in output? - deanhystad - Jun-27-2022 My guess is the occasional blank like is from something you did not post. I would comment out the print and see if the blank lines still appear. RE: Why the blank lines in output? - Mark17 - Jun-27-2022 (Jun-27-2022, 06:37 PM)deanhystad Wrote: My guess is the occasional blank like is from something you did not post. I would comment out the print and see if the blank lines still appear. That whole block looks like this: if current_date != current_date_prev: #debug daily_mode_counter += 1 print(f'current_date is {current_date}, common date is {datetime.utcfromtimestamp(current_date*86400).strftime("%Y-%m-%d")}, trade status is {trade_status}, and control flag is {control_flag}123456789.') current_date_prev = current_date if daily_mode_counter > 500: raise ValueError('daily_mode_counter > 100') #I forgot to include a line to increment counter on each pass else: passOnly the ValueError prints out if I comment out L3. RE: Why the blank lines in output? - deanhystad - Jun-27-2022 I still think the blank line is from elsewhere. I would comment out the print statement and see if you still get blank lines occasionally printing out. RE: Why the blank lines in output? - DeaD_EyE - Jun-27-2022 There must be elsewhere a print call in your code.Maybe (hopefully not) from the library itself you're using. print(f'current_date is {current_date}, common date is {datetime.utcfromtimestamp(current_date*86400).strftime("%Y-%m-%d")}, trade status is {trade_status}, and control flag is {control_flag}.')If control_flag has a newline, then you should see the following: But you don't have a dot, so control_flag has no newline.The newline comes from elsewhere. RE: Why the blank lines in output? - Mark17 - Jun-27-2022 control_flag is an 11-character string. I do have other print lines in the program, though, so I will look closely and try to pin it down. It's good to know the blank lines wouldn't be random or the result of any memory limitation or anything like that. Thanks to you both! |