Jump to content

- - - - -

Simple Python Help - Phrasing File

  • Please log in to reply
1 reply to this topic

#1 steelchizzle


    New Member

  • New Members
  • 6 posts

Posted 21 August 2017 - 12:25 AM

Hello every one how’s tricks? I hope all is well!! I look forward to been able to post more once my limit is lifted J .


Ok so I need some help with a little python, my skills with python are very basic. I am doing my research besides here.


 My code is very basic and I intend on keeping it that way if possible. Short  N Sweet J.


Long story short, I want to

1. Open a file in this case a text file that was created from a xml documented (Copy And Pasted, don’t ask.) !!  (I have this much completed)


                     So the contents of this text file will be the xml code.


2. Scan the text file line by line or how ever for any content between two quotation marks and set this content to two separate variables. There are two sets of quotation marks per line.


                    Example <Brand Name =”Toyota” Value =”100.0” />


                    I would like for var1=Toyota  and  var2=100.0.


                    But the content of the file changes every time so it cannot be predicted easily with a pattern.


                    I have this completed, but everything is stored in one single variable e.g. ( var1=Toyota100.0 ),  I would like two separate variables for each value.


3. And simply print out the contents of the separate variables to screen and I can format them then after how I like.


                   I have this completed – But printing out the one single variable only and its messy.



If I can achieve this my task is pretty much finished.


Regardless if I receive help here or not I will still post my solution here as it might help others !. Thanks Ladies and Gentlemen !!


By the way I can only post so much untill my limit is lifted so please keep that in mind if I don't reply, I think I can edit at least one so its not that bad.


I also have a few books im reading for this if I find anything interesting I will be sure to reference it.


Again Thanks every one - I really do appreciate all the help here ! 


My Code Is Below.




import re


 infile = open("inputFile.txt", "r")  # Open Input File





    lines = infile.readlines(count)


    newLines = str (lines)  # Needs to be a string for re.findall


    var1  = re.findall(r'"([^"]*)"', newLines)




    count +=1





#2 ARandomOWL


    Wise Owl

  • FW Team Member
  • PipPipPipPip
  • 1458 posts
  • Gender:Male
  • Location:UK

Posted 21 August 2017 - 09:58 AM

As usual with Python, there's a library for that! Have a look here: https://docs.python....lementtree.html


I'm sure there will be alternatives too. Good luck!

4670k + GTX 980Ti -- crammed into a mini-ITX case

Arch Linux

About Me