Reputation: 165
So I want to write to a file instead of printing to the screen. I'm having trouble with doing that with python 2.7.
Here is my script:
from xml.dom import minidom
import sys
import os
xmldoc = minidom.parse('c:/Python27/file.xml')
itemlist = xmldoc.getElementsByTagName('User')
for s in itemlist:
print (s.attributes['name'].value)
This actually prints out perfectly I just need it to print to a file. I'm sort of running into some issues.
Upvotes: 0
Views: 51
Reputation: 6592
I'm no python expert but you should be able to open the source file and then write the string to it
f = open(filename, 'w')
for s in itemlist:
f.write(s.attributes['name'].value + "\n")
Upvotes: 2