0

I grabbed an array from the lines of a txt file. The problem is I only need the end of these lines. I'm still pretty new to Python so I'm not sure how to put these concepts together. Below is my best attempt, the first part works but the second falls apart.

 with open("prices.txt") as f:
        readline = f.readlines()

 for seatCapacity in readline:
        seatCapacity = readline[10:]
Amanda
  • 43
  • 4

1 Answers1

2

I guess, you want like this.

with open("prices.txt") as f:
     for line in f: 
     seatCapacity = line[10:]

you can refer this solution: How should I read a file line-by-line in Python?

Lucky
  • 875
  • 1
  • 9
  • 19
  • 1
    If the asker is new to Python, perhaps add that ``line[10:]`` will skip the 10 first items (i.e. characters) in the row. In the same spirit, ``line[-10:]`` will read the _last_ 10 characters. See [this question](https://stackoverflow.com/a/509295/1144382) for more info on _slicing_. – Thomas Fauskanger Dec 09 '17 at 01:22
  • Is this supposed to create an array? I might be misunderstanding but this seems to just replace seatCapacity with every iteration. – Amanda Dec 09 '17 at 02:23