Python3 :how to import data from one text file into a few different arrays? The number of arrays needs to be given by another parameter n ,and the shape of arrays are diffrent.
Asked
Active
Viewed 37 times
-2
-
Clarify what you are talking about with an example. Your language is unclear - it is impossible to import a name into a datastructure. You can import a name and then put the value it refers to inside a data structure. Is that what you want? – timgeb Dec 26 '17 at 14:03
-
I mean i saved a lot of point coordinates in a text file(one point's (x,y) in each line),and i wanna import these coordinates into a few different arrays. The number of arrays is given by an parameter n, and the shapes of these arrays are different. – Jason Wong Dec 26 '17 at 14:33
-
Ok what's stopping you? Show us an example input file, your code, the output/result, and how the output/result differs from what you want. – timgeb Dec 26 '17 at 14:35
1 Answers
0
You can split line with , like
lines = text_file.read().split(',')
or with each line
f = open('file_name.ext', 'r')
x = f.readlines()
Check post for more How to read text file into a list or array with Python

Adam Bahrani
- 65
- 3
- 11