Answer the question
In order to leave comments, you need to log in
How to convert numbers from a file to variables?
There is a file (txt) in which files are written in this form:
0 0 1 1 should be equal to x1 y1 r1 v1
223 52 1 1 should be equal to x2 y2 r2 v2
As I understand it, you need to select by spaces. But already when opening in python 'open()'
and outputting through for, it outputs as a two-dimensional array, and not a string.
In principle, it could do, but this code would be as long as all calculations with this data))
Answer the question
In order to leave comments, you need to log in
via for it outputs as a two dimensional array and not a string
variables = {}
with open('ttt', 'r') as f:
for l in f:
values, names = l.split('----')
print(values, names)
d = dict(zip(names.split(), values.split()))
variables.update(d)
print(variables)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question