Python Forum
parse/read from file seperated by dots
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parse/read from file seperated by dots
#3
Thanks your very much, that was what I was looking for Smile
Now I have to learn the details you have implemented it Shy

I have tested to loop over the "Steps": Working well
    print(len(root['Step']))    
    for item in root['Step']:
        print(item + " ---> " + root['Step'][item]['Progress'].data + " ---> " + root['Step'][item]['Result'].data)
Output:
2 1 ---> finished ---> good 2 ---> finished ---> error
One question, I'm struggling to get it really from file.
You used embedded in the code:
file = io.StringIO('''\
Step.1 = Tas...
How to get it from the separate file "File.txt"?
If I use:
file = open('File.txt')
I get:
Output:
Traceback (most recent call last): File "f:\python_test\parse.py", line 30, in <module> root = parse(file) File "f:\python_test\parse.py", line 20, in parse lvalue, rest = line.split('=', maxsplit=1) ValueError: not enough values to unpack (expected 2, got 1)
Reply


Messages In This Thread
RE: parse/read from file seperated by dots - by giovanne - Jun-23-2023, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 299 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 2,989 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  parse json field from csv file lebossejames 4 816 Nov-14-2023, 11:34 PM
Last Post: snippsat
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,632 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,188 Jul-06-2023, 01:52 AM
Last Post: Tupa
  Formatting a date time string read from a csv file DosAtPython 5 1,436 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 7,374 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Read csv file with inconsistent delimiter gracenz 2 1,255 Mar-27-2023, 08:59 PM
Last Post: deanhystad
  Read text file, modify it then write back Pavel_47 5 1,727 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  Correctly read a malformed CSV file data klllmmm 2 2,092 Jan-25-2023, 04:12 PM
Last Post: klllmmm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020