Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Files handling and lists
#11
Okay, but fout just creates a file without the header. It doesn't change data. If you want to skip the first row, just loop over data[1:].

You might want to check out the csv module. It is made to handle files like this, and can handle skipping the first row and splitting by tabs for you.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#12
(Oct-09-2018, 12:52 AM)ichabod801 Wrote: Okay, but fout just creates a file without the header. It doesn't change data. If you want to skip the first row, just loop over data[1:].

You might want to check out the csv module. It is made to handle files like this, and can handle skipping the first row and splitting by tabs for you.

okay I fixed that issue but I have one more question. You showed me how to skip the first row in the loop. Can that same loop also skip the last line? because for
long = line[1]
the last line in that reads 'N/A' which cannot be turned into an integer for obvious reasons
Reply
#13
Sure. -1 is the index for the last element in a list. So just loop over data[1:-1].
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 1,431 Nov-25-2023, 05:31 AM
Last Post: Iqratech
Star python exception handling handling .... with traceback mg24 3 1,215 Nov-09-2022, 07:29 PM
Last Post: Gribouillis
  Handling pdf files with python. fuzzin 1 1,217 Jan-19-2022, 02:24 PM
Last Post: ThiefOfTime
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 2,756 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,312 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  Handling Large XML Files (>10GB) in Python onlydibs 1 4,136 Dec-22-2019, 05:46 AM
Last Post: Clunk_Head
  How to concatenate files while looping through lists? python_newbie09 3 2,822 Mar-24-2019, 03:11 PM
Last Post: python_newbie09
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,186 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

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