Python Forum
Why the blank lines in output?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why the blank lines in output?
#1
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_date
Here's a segment of the output:

Output:
current_date is 14692, common date is 2010-03-24, trade status is INCEPTION, and control flag is find_spread. current_date is 14693, common date is 2010-03-25, trade status is IN_TRADE, and control flag is update_long. current_date is 14694, common date is 2010-03-26, trade status is IN_TRADE, and control flag is update_long. current_date is 14697, common date is 2010-03-29, trade status is IN_TRADE, and control flag is update_long. current_date is 14698, common date is 2010-03-30, trade status is IN_TRADE, and control flag is update_long. current_date is 14699, common date is 2010-03-31, trade status is IN_TRADE, and control flag is update_long. current_date is 14700, common date is 2010-04-01, trade status is IN_TRADE, and control flag is update_long. current_date is 14704, common date is 2010-04-05, trade status is IN_TRADE, and control flag is update_long. current_date is 14705, common date is 2010-04-06, trade status is IN_TRADE, and control flag is update_long. current_date is 14706, common date is 2010-04-07, trade status is IN_TRADE, and control flag is update_long. current_date is 14707, common date is 2010-04-08, trade status is INCEPTION, and control flag is find_spread. current_date is 14733, common date is 2010-05-04, trade status is INCEPTION, and control flag is find_spread. current_date is 14734, common date is 2010-05-05, trade status is IN_TRADE, and control flag is update_long. current_date is 14735, common date is 2010-05-06, trade status is IN_TRADE, and control flag is update_long. current_date is 14736, common date is 2010-05-07, trade status is IN_TRADE, and control flag is update_long.
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.
Reply
#2
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.
Reply
#3
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.
Reply
#4
(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: pass
Only the ValueError prints out if I comment out L3.
Reply
#5
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.
Mark17 likes this post
Reply
#6
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:
Output:
current_date is 14698, common date is 2010-03-30, trade status is IN_TRADE, and control flag is update_long .
But you don't have a dot, so control_flag has no newline.
The newline comes from elsewhere.
Mark17 likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to insert Dashed Lines in between Rows of a tabulate output Mudassir1987 0 507 Sep-27-2023, 10:09 AM
Last Post: Mudassir1987
  Remove Blank Lines from docx table and paragraphs bsudhirk001 1 3,711 Feb-14-2021, 12:38 AM
Last Post: Larz60+
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 5,856 Aug-10-2020, 11:01 PM
Last Post: medatib531
  CSV gives me blank row on PC, but not a Mac bazcurtis 2 2,799 Jan-06-2020, 08:40 AM
Last Post: buran
  re.finditer issue, output is blank anna 1 2,374 Feb-07-2019, 10:41 AM
Last Post: stranac
  25 blank lines in my sorted_fruits output list! raven61 7 4,287 Aug-09-2018, 11:30 PM
Last Post: raven61

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020