Python Forum
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Slicing to a file
#5
(May-12-2017, 03:49 AM)nilamo Wrote: Get rid of lines 5 and 6.  They do nothing, but open file handles that you never deal with.

I'd suggest massively simplifying your task, and just using strings instead of files.  Once it works, then you can add in file handling.
Something like:
in_lines = '''There once was a time bygone,
Way back in computing’s dawn.
The language was Lisp,
Its functions were crisp,
But its parentheses went on and on and on.

There once was a language named Perl,
That Larry Wall thought would take over the world.
But the syntax was homely,
And often write-only,
And reading your code would make you hurl.

Then came the wind to our sails,
In a language that every hipster hails.
Its name was Ruby,
It made an expert from a newbie,
Until it got traffic and it fell off the rails.'''.split("\n")

skip_first_lines = 3
skip_last_lines = 5

out_lines = []
# build the output

# next steps:
# get input from a file
# save output to a file
# get skip numbers from user
So would turning the text files text into a list and then using something similar to that code work?
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