Python Forum
Why there's a 'blank line' on CSV file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why there's a 'blank line' on CSV file?
#1
Exclamation 
Hello guys,

With the following code I'm exporting my data to a CSV file:
from tempfile import NamedTemporaryFile
from FlightRadar24.api import FlightRadar24API
from time import time, sleep
from datetime import datetime
import shutil
import csv
import threading
import schedule 
import time 
import sched, time

s = sched.scheduler(time.time, time.sleep)
def do_something(sc): 
    print("Doing stuff...")

    now = datetime.now()
    dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
    company1 = len(fr_api.get_flights(airline = 'AZU'))
    company2 = len(fr_api.get_flights(airline = 'GLO'))
    company3 = len(fr_api.get_flights(airline = 'LAN'))
    company4 = len(fr_api.get_flights(airline = 'PTB'))
    
    print(dt_string, company1, company2, company3, company4)
    fields=[dt_string,company1,company2,company3,company4]


    with open(r'C:\Users\bruno\Desktop\Voos\Voos.csv', 'a') as f:
        writer = csv.writer(f, delimiter=';')
        writer.writerow(fields)   

    
    s.enter(60, 1, do_something, (sc,))

s.enter(60, 1, do_something, (s,))
s.run()
When I print it, I get the values line by line...
print(dt_string, company1, company2, company3, company4)


23/03/2021 09:09	50	18	34	1				
23/03/2021 09:09	50	18	34	1				
23/03/2021 09:09	50	19	34	1				
23/03/2021 09:09	50	19	34	1				
23/03/2021 09:09	50	19	34	1				
23/03/2021 09:09	51	19	34	1				
23/03/2021 09:09	51	19	34	1				
23/03/2021 09:09	51	19	34	1
But when I open my csv file, the results are separated by an empty line... like this:
23/03/2021 09:09	50	18	34	1
				
23/03/2021 09:09	50	18	34	1
				
23/03/2021 09:09	50	19	34	1
				
23/03/2021 09:09	50	19	34	1
				
23/03/2021 09:09	50	19	34	1
				
23/03/2021 09:09	51	19	34	1
				
23/03/2021 09:09	51	19	34	1
				
23/03/2021 09:09	51	19	34	1
What's going on?
How can I fix it, and get the values on my csv file without the blank line?

Thank you!
Reply


Messages In This Thread
Why there's a 'blank line' on CSV file? - by brunolelli - Mar-24-2021, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,564 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Getting last line of each line occurrence in a file tester_V 1 867 Jan-31-2023, 09:29 PM
Last Post: deanhystad
  python insert blank line in logger mg24 1 2,836 Nov-02-2022, 08:36 AM
Last Post: snippsat
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,377 Sep-27-2022, 01:38 PM
Last Post: buran
  Print to a New Line when Appending File DaveG 0 1,221 Mar-30-2022, 04:14 AM
Last Post: DaveG
  Find and delete above a certain line in text file cubangt 12 3,481 Mar-18-2022, 07:49 PM
Last Post: snippsat
  CSV to Text File and write a line in newline atomxkai 4 2,693 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  writelines only writes one line to file gr3yali3n 2 2,376 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  [Solved] Reading every nth line into a column from txt file Laplace12 7 5,229 Jun-29-2021, 09:17 AM
Last Post: Laplace12
  blank graph with matplotlib from a csv file / data type issue arsentievalex 0 1,955 Apr-06-2021, 10:08 AM
Last Post: arsentievalex

Forum Jump:

User Panel Messages

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