Skip to content
Advertisement

Extracting various variables from a file in Python

I have a file that looks like

JavaScript

I would like to extract the values of “A”, “B”, “C”, the last value of “E. E.” and all values of “a_{i}” and “a_{i}a_{j}”. To get A, B, and C, I have used this code as I know exactly the lines’ numbers

JavaScript

How can I extract the rest? For the last “E.E.” the output should be “0.00751656967834972”. For “a_{i}” and “a_{i}a_{j}”, I would like to have an array with indices i and j as well as the values of each variable.

Advertisement

Answer

How about using dictionaries instead of creating variables on the fly?

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement