Hi,I am new to Python, but learning. (Hopefully the layout is readable)
I am having trouble getting two scripts to work together. What I want to do is
have the combinded script do the following:
1. Read through a directory of xml files, not a single file, but many xml
files.2. Read each files contents.3. Pull out the <uicontrol> element content
(words between open and close tag)
* For example: <uicontrol>Sam was here.</uicontrol>
* The script would pull out the content "Sam was here" and print it to a
file.
My scripts so
far:----------------------------------------------------------Script to get
<uicontol>
content----------------------------------------------------------import
xml.etree.ElementTree as ET
tree = ET.parse('TEST.xml')
root = tree.getroot()for uicontrol in root.iter('uicontrol'):
print(uicontrol.text)
----------------------------------------------------------Script to read
through the
files:----------------------------------------------------------import sys
import glob
import errnopath
='/Users/sastarfa/Documents/Projects/Script-projects/Scripts/Pull-out-terms-between-elements/*.xml'
files = glob.glob(path)
for name in files: # 'file' is a builtin type, 'name' is a
less-ambiguousvariable name.
try:
with open(name) as f: # Noneed to specify 'r': this is the default.
sys.stdout.write(f.read())
This is the area I get stuck. I can understand, write a script to run on one a
single file you input into the script, but getting a script to run on a
directory I am not understanding how to do this.
Thanks in advance for any and all help.Really appreciate the help.
Sam
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor