Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slicing to a file
#1
Hey everyone just a quick question. I need to omit lines from a file where the number of lines is dictated by the user input then save it as a new file
I have the jist of editing files and saving them which is fine I would just really appreciate some clarification on how to remove lines since im not sure if there is a delete funtion...
Here is what I have so far maybe I am missing something simple.

import sys
print(" *** Truncating File Copy ***")
infile_name = input("Please enter the name of the file to copy: ")
outfile_name = input("Please enter the name of the new copy:  ")
infile = open(infile_name, 'r', errors = 'ignore')
outfile = open(outfile_name, 'w')
def lines(): [i for i in infile.readlines()]
lines()
outfile = open(outfile_name, 'w')
def omit():
        omitline = (input("Omit how many lines from the start:"))
        for num in omitline:
            outfile.write('\t')
infile = open(infile_name, 'r', errors = 'ignore')
outfile = open(outfile_name, 'w')
omit()
outfile.write(infile.read())
infile.close()
outfile.close()
Reply


Messages In This Thread
Slicing to a file - by Liquid_Ocelot - May-11-2017, 09:05 PM
RE: Slicing to a file - by nilamo - May-11-2017, 09:34 PM
RE: Slicing to a file - by Liquid_Ocelot - May-11-2017, 09:47 PM
RE: Slicing to a file - by nilamo - May-12-2017, 03:49 AM
RE: Slicing to a file - by Liquid_Ocelot - May-12-2017, 06:15 AM
RE: Slicing to a file - by nilamo - May-12-2017, 02:42 PM
RE: Slicing to a file - by Liquid_Ocelot - May-12-2017, 10:51 PM
RE: Slicing to a file - by ichabod801 - May-14-2017, 01:01 PM
User input slice - by Liquid_Ocelot - May-13-2017, 11:12 AM
RE: User input slice - by ichabod801 - May-13-2017, 11:50 AM
RE: User input slice - by Liquid_Ocelot - May-13-2017, 08:54 PM
RE: User input slice - by Liquid_Ocelot - May-13-2017, 10:51 PM

Forum Jump:

User Panel Messages

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