trying to use sax for a very basic first xml parser

Discussion in 'Python' started by manu, Jul 14, 2008.

  1. manu

    manu Guest

    Hi,

    I need to parse xml files for the Blender Game Engine. ATM I am trying
    to get this script running in the BGE. This is my first script and I
    dont have much experience programming...

    import xml.sax

    class PnmlHandler(xml.sax.ContentHandler):
    def __init__(self):
    self.inPlace=0

    def startElement(self, name, attrs):
    if name != "place": return
    if attrs.getLength()==0: return

    print 'Starting element:', name
    print "attrs:", attrs.keys()
    id = attrs.get("id", None)
    print "id:", id

    if name == "place":
    self.inPlace=1

    def endElement(self, name):
    if name == "place":
    self.inPlace=0



    parser = xml.sax.make_parser()
    parser.setContentHandler(PnmlHandler())
    parser.parse(open("bpm.pnml","r"))

    this works in the IDLE ide. Output:

    Starting element: place
    attrs: [u'id']
    id: p9723441
    Starting element: place
    attrs: [u'id']
    id: p26811937
    Starting element: place
    attrs: [u'id']
    id: p24278422[/code]

    but when I copy the script into blender and run it I get:

    Code:
    Compiled with Python version 2.5.
    Checking for installed Python... got it!
    Traceback (most recent call last):
      File "Text", line 27, in <module>
      File "H:\Python25\lib\xml\sax\__init__.py", line 93, in make_parser
        raise SAXReaderNotAvailable("No parsers found", None)
    xml.sax._exceptions.SAXReaderNotAvailable: No parsers found
    Its probably a stupid question but thanks anyway!
     
    manu, Jul 14, 2008
    #1
    1. Advertising

  2. manu

    Miki Guest

    Hello,

    > but when I copy the script into blender and run it I get:
    >
    >
    Code:
    Compiled with Python version 2.5.
    > Checking for installed Python... got it!
    > Traceback (most recent call last):
    >   File "Text", line 27, in <module>
    >   File "H:\Python25\lib\xml\sax\__init__.py", line 93, in make_parser
    >     raise SAXReaderNotAvailable("No parsers found", None)
    > xml.sax._exceptions.SAXReaderNotAvailable: No parsers found

    Python is using an external library for SAX (expat IIRC).
    I *guess* the Python that comes with Blender don't have this library.

    > Its probably a stupid question but thanks anyway!

    He who asks is a fool for five minutes, but he who does not ask
    remains a fool forever.
    - Chinese Proverb

    HTH,
    --
    Miki <>
    http://pythonwise.blogspot.com
     
    Miki, Jul 14, 2008
    #2
    1. Advertising

  3. manu

    manu Guest

    On Jul 14, 8:14 pm, Miki <> wrote:


    > Python is using an external library for SAX (expat IIRC).
    > I *guess* the Python that comes with Blender don't have this library.
    >

    I don't know... I didnt install any external libraries for sax. I
    think python comes with a standard sax library.
    And before I had python installed Blender said at startup:
    "Compiled with Python version 2.5.
    Checking for installed Python... No installed Python found.
    Some scripts will not run. Continuing happily"

    After installing Python 2.5.2 it now says:
    "Compiled with Python version 2.5.
    Checking for installed Python... got it!"
    So I think it is using the installed Python.

    Could it be that I have to install the same python version Blender was
    compiled with?
     
    manu, Jul 14, 2008
    #3
  4. manu

    Miki Guest

    Hello,

    > Could it be that I have to install the same python version Blender was
    > compiled with?

    I have no idea.

    May I suggest you ask in the blender list?

    HTH,
    --
    Miki <>
    http://pythonwise.blogspot.com
     
    Miki, Jul 15, 2008
    #4
  5. manu

    manu Guest


    >
    > May I suggest you ask in the blender list?
    >


    Will do that and report back. Thank you!

    Manuel
     
    manu, Jul 15, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond Arthur St. Marie II of III

    very Very VERY dumb Question About The new Set( ) 's

    Raymond Arthur St. Marie II of III, Jul 23, 2003, in forum: Python
    Replies:
    4
    Views:
    484
    Raymond Hettinger
    Jul 27, 2003
  2. Peter

    Very very very basic question

    Peter, Feb 8, 2005, in forum: C Programming
    Replies:
    14
    Views:
    520
    Dave Thompson
    Feb 14, 2005
  3. Sanjeev
    Replies:
    4
    Views:
    1,451
    Stanimir Stamenkov
    May 4, 2008
  4. Lew
    Replies:
    2
    Views:
    336
    Arne Vajhøj
    Jul 22, 2011
  5. Erik Wasser
    Replies:
    5
    Views:
    465
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page