Python Forum
25 blank lines in my sorted_fruits output list!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
25 blank lines in my sorted_fruits output list!
#1
25 blank lines in my sorted_fruits output list don't know how to get rid of them! Don't know how they got there!here is my script
# This just gives you a feel that something is happening.
print('Sorting started')

# This defines where the ipnput and output files are
fin = open('unsorted_fruits.txt', 'r')
fout = open('sorted_fruits.txt', 'w')

# This reads the input file
Fruits = fin.readlines()

# This sorts the input file
Fruits.sort()

# This for loop writes the fruits to the sorted_fruits list.
for fruit in Fruits:
        fout.write(fruit)

# This cloes both files.
fin.close()
fout.close()

# This just lets you know that the sorting is finished.
print('Sorting finished')
If you run it the output sorted_fruits.txt file has 25 empty lines and then the list starts. This was for home work but i've already turned it in I just want to know if I can get the lines removed? I can't figure it out.
Reply


Messages In This Thread
25 blank lines in my sorted_fruits output list! - by raven61 - Aug-08-2018, 05:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to insert Dashed Lines in between Rows of a tabulate output Mudassir1987 0 1,258 Sep-27-2023, 10:09 AM
Last Post: Mudassir1987
  Why the blank lines in output? Mark17 6 2,872 Jun-27-2022, 11:21 PM
Last Post: Mark17
  sum() list from SQLAlchemy output Personne 5 7,233 May-17-2022, 12:25 AM
Last Post: Personne
Exclamation Why there's a 'blank line' on CSV file? brunolelli 4 5,211 Mar-25-2021, 03:43 AM
Last Post: buran
  Remove Blank Lines from docx table and paragraphs bsudhirk001 1 5,332 Feb-14-2021, 12:38 AM
Last Post: Larz60+
  How to append to list a function output? rama27 5 9,430 Aug-24-2020, 10:53 AM
Last Post: DeaD_EyE
  Iterate 2 large text files across lines and replace lines in second file medatib531 13 9,601 Aug-10-2020, 11:01 PM
Last Post: medatib531
  json.dumps list output qurr 12 7,653 Apr-08-2020, 10:13 PM
Last Post: micseydel
  how do i get rid of next lines in my list() ironpotatoe58 10 5,894 Mar-31-2020, 03:57 AM
Last Post: SheeppOSU
  If item in list = true, Output = xx kroh 0 1,918 Feb-19-2020, 09:17 AM
Last Post: kroh

Forum Jump:

User Panel Messages

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