Last active
March 5, 2019 15:33
-
-
Save crowesn/ed56d1b8ef525949087496e506ca336f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
tree = ET.parse('thorpe.xml') | |
root = tree.getroot() | |
for item in root.iter('DISS_para'): | |
abstract = (item.text) | |
myList = [abstract.split('\t')] | |
''.join(map(str,myList)) | |
print(abstract) |
That's amazing! It works!
Trying to add it to a CSV file, but it's parsing every letter. Not sure what I'm doing wrong.
import xml.etree.ElementTree as ET
import re
import csv
forCSV =[]
forCSV.append(['abstract'])
tree = ET.parse('thorpe.xml')
root = tree.getroot()
combined_abstracts = ""
for item in root.iter("DISS_para"):
combined_abstracts += re.sub('\t', '', item.text)
forCSV.append(combined_abstracts)
with open('outputFile.csv', 'w', newline='') as csvfile:
wr = csv.writer(csvfile, delimiter=',')
wr.writerows(forCSV)
sorry, that indentation is all fucked up
thanks, I found my mistake! you're a wizard!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you wanted to replace the tabs with a space: