Forum Stats

  • 3,735,086 Users
  • 2,247,101 Discussions
  • 7,857,679 Comments

Discussions

Python Programming help please

779796
779796 Member Posts: 1
edited Jun 21, 2010 5:55PM in Python
Hi there,

I got this txt file with following contents:

<GLOSSARY>
<INFO>
<NAME>My Glossary</NAME>
<INTRO>stuff</INTRO>

The above text is saved in test.txt file.

I need to write a python script that would load the above file as list of strings. I then need display only the text from <Name> to </Name> in python.

If anybody can help me please with the code. I've tried searching a lot but haven't found anything.

Thank You

Answers

  • 390020
    390020 Member Posts: 446
    What you call a text file, it looks to me like a xml file :)
    There are plenty of useful resources in the web to help you out with this kind of common situation. One of the easiest explanations out there is Dive into Python by Mark Pilgrim: http://diveintopython.org/xml_processing/
    ElementTree is part of the standard lib now so you can take full advantage of it. Please start reading from here:
    http://effbot.org/zone/element-index.htm#usage

    Good luck
This discussion has been closed.