May-11-2017, 09:05 PM
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.
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()