Python Forum

Full Version: read from txt file and get variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi. i'm newbie in python and need some help

I have a txt file like with a structure like that below

####inputs
###bla-bla-bla

xpto = 2
zzz = 10.25
name = Jonh
###

interval = 2
....

#####
How can I do in python to open the file, and get the variables as strings that have the equal sign (=)
open the file:
read line by line:
use:
if '=' in line:
    # do this ...
how to I open the file
how do i read the line by line?
thanks
You need to learn the basics, suggest: https://www.python-course.eu/

with open('filename', 'r') as f:
    for line in f:
        ...