You are not logged in.
Pages: 1
Ok, I'm an infant in Python and I've got a problem that is driving me nuts.
I download a xml page(with terrible formatting), then use xslt to format the page into a workable form, and save the result to a new file. But when I try to read the new file so that I can parse it, I get "Permission denied" messages. I have something like this:
def formatPage():
styledoc = libxml2.parseFile(whatever.xslt)
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.parseFile(foo)
result = style.applyStylesheet(doc, None)
style.saveResultToFilename(foo_bar, result, 0)
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
def parsePage():
temp_file = os.popen(foo_bar)
file = temp_file.read()
I'm assuming that "foo_bar" is still open by xslt and that's why I can't read the file. But for the life of me, I can't figure out how to relinquish control of the file.
Thanks for any help.
Hi. I'm a sig. What are you?
Offline
I may be misinterpreting your intentions, but to os.popen is for running external commands (opens a pipe) and doesn't return a file object.
To read a file:
foobar = 'a_file.txt'
temp_file = open(foo_bar)
filecontents = temp_file.read()
Offline
Yes, I would do it the same was as aroo is mentioning
Offline
I may be misinterpreting your intentions, but to os.popen is for running external commands (opens a pipe) and doesn't return a file object.
To read a file:
foobar = 'a_file.txt' temp_file = open(foo_bar) filecontents = temp_file.read()
Doh! Now I feel silly. :oops: Originally I was reading straight from stdout and forgot to fix that when I realized I would have to read from a file.
Thanks arooaroo and twiistedkaos.
Hi. I'm a sig. What are you?
Offline
Pages: 1