Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 read from txt file and get variables
#1
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 (=)
Quote
#2
open the file:
read line by line:
use:
if '=' in line:
    # do this ...
Quote
#3
how to I open the file
how do i read the line by line?
thanks
Quote
#4
Check our tutorial here https://python-forum.io/Thread-Basic-Files
Quote
#5
You need to learn the basics, suggest: https://www.python-course.eu/

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Read and save file in chucksize zinho 1 66 Mar-27-2020, 02:31 PM
Last Post: zinho
  Recommended way to read/create PDF file? Winfried 1 129 Mar-17-2020, 03:17 PM
Last Post: Larz60+
  how to read json file jk91 34 1,223 Feb-26-2020, 08:10 AM
Last Post: jk91
  Read Yaml configuration file in Python binhduonggttn 1 178 Feb-11-2020, 05:43 AM
Last Post: ndc85430
  Simple Read File Issue blackjesus24 4 200 Feb-09-2020, 12:07 AM
Last Post: blackjesus24
  Read csv file data parthi1705 0 142 Jan-29-2020, 01:42 PM
Last Post: parthi1705
  Importing variables from another file IILawrenceII 7 700 Jan-18-2020, 12:31 PM
Last Post: IILawrenceII
  search and read file given partial file SriRajesh 2 161 Jan-07-2020, 04:56 PM
Last Post: snippsat
  txt-file: read and append missing data sufi 1 245 Dec-07-2019, 08:12 AM
Last Post: Gribouillis
  Read csv file, parse data, and store in a dictionary markellefultz20 4 523 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE

Forum Jump:


Users browsing this thread: 1 Guest(s)