I need to read in a file of sets of coordinates using Python. The first line will have a number, n, which is the number of coordinate sets that need to be read. Following the first line will be n lines, where each line contains a single coordinate pair.
Example (in this case, n =4):
n
(x,y)
(x,y)
(x,y)
(x,y)
The catch is that there will be multiple sections in the file. So the first n might be 10, with 10 sets of coordinates, and the next n might be 20, with 20 sets of coordinates following it.
As of right now I’m just reading the sections of coordinates in separately, but I would like it if I could any number of sections of coordinates in the file I’m reading in.
You can use
open()to open a file for reading,readline()to read file content line by line, andint()to convert from a string to an integer.Here’s an example implementation using these parts: