Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slicing to a file
#10
(May-13-2017, 11:50 AM)ichabod801 Wrote: You've pretty much got right there. If you've just got one list (and please don't name it list), then you can eliminate the for loops and it should work. Although, the second question should be "... from the end".

Hmm ok then I really am not sure why this won't work... I basically need to do exactly what I was saying in the first post but for a text file
here is the code I have but the output just stays the same as the old file when copied to a new file no changes
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')
file = open (infile_name, 'r', errors = 'ignore')
newList = file.readlines()
def omit():
        omitline = int(input("Omit how many lines from the start:"))
        for num in range (omitline):
            newList[omitline:]
def omit2():
        omitline2 = int(input("Omit how many lines from the end:"))
        for num in range (omitline2):
            newList[:omitline2]
infile = open(infile_name, 'r', errors = 'ignore')
outfile = open(outfile_name, 'w')
omit()
omit2()
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