You are not logged in.

#1 2006-12-19 18:05:56

vredfreak
Member
Registered: 2004-11-20
Posts: 66

Python and xslt

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

#2 2006-12-19 20:11:45

arooaroo
Member
From: London, UK
Registered: 2005-01-13
Posts: 1,268
Website

Re: Python and xslt

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

#3 2006-12-19 21:07:02

twiistedkaos
Member
Registered: 2006-05-20
Posts: 666

Re: Python and xslt

Yes, I would do it the same was as aroo is mentioning

Offline

#4 2006-12-19 23:22:39

vredfreak
Member
Registered: 2004-11-20
Posts: 66

Re: Python and xslt

arooaroo wrote:

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

Board footer

Powered by FluxBB