N
N
Nikolai Sidorenko2014-11-27 19:54:45
Python
Nikolai Sidorenko, 2014-11-27 19:54:45

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

1 answer(s)
S
sim3x, 2014-11-27
@NSidorov

via for it outputs as a two dimensional array and not a string

it displays not a two-dimensional array, but just an array
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)

What is the task?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question