where is the Write method of ElementTree??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gray.bowman@gmail.com

    where is the Write method of ElementTree??

    I'm messing around with trying to write an xml file using
    xml.etree.Eleme ntTree. All the examples on the internet show the use
    of ElementTree.wri te(), although when I try to use it it's not
    available, gives me ...

    ElementTree(sec tionElement).wr ite("section.xm l")
    TypeError: 'module' object is not callable


    I'm new to python, so I think I'm doing something wrong.. any
    thoughts?

    Thanks.'


    See code below:

    # Create xml structure
    sectionElement = ElementTree.Ele ment("section")

    # step through feed result and create elements for each article -
    result[article]
    for article in feedResult:
    articleElement = ElementTree.Ele ment("article")

    titleElement = ElementTree.Sub Element(article Element, "title")
    titleElement.te xt = article['title']

    bodyElement = ElementTree.Sub Element(article Element, "body")
    bodyElement.tex t = article['body']

    sectionElement. append(articleE lement)

    #print ElementTree.tos tring(sectionEl ement)
    ElementTree(sec tionElement).wr ite("section.xm l")
  • John Machin

    #2
    Re: where is the Write method of ElementTree??

    On May 23, 6:56 am, gray.bow...@gma il.com wrote:
    I'm messing around with trying to write an xml file using
    xml.etree.Eleme ntTree. All the examples on the internet show the use
    of ElementTree.wri te(), although when I try to use it it's not
    available, gives me ...
    >
    ElementTree(sec tionElement).wr ite("section.xm l")
    TypeError: 'module' object is not callable
    >
    I'm new to python, so I think I'm doing something wrong.. any
    thoughts?
    >
    Thanks.'
    >
    See code below:
    >
    # Create xml structure
    sectionElement = ElementTree.Ele ment("section")
    >
    # step through feed result and create elements for each article -
    result[article]
    for article in feedResult:
    articleElement = ElementTree.Ele ment("article")
    >
    titleElement = ElementTree.Sub Element(article Element, "title")
    titleElement.te xt = article['title']
    >
    bodyElement = ElementTree.Sub Element(article Element, "body")
    bodyElement.tex t = article['body']
    >
    sectionElement. append(articleE lement)
    >
    #print ElementTree.tos tring(sectionEl ement)
    ElementTree(sec tionElement).wr ite("section.xm l")
    It's complaining about
    ElementTree(wha tever)
    As it says, you are trying to call a module.

    Looks like you need:
    sectionElement. write("section. xml")

    HTH,
    John

    Comment

    • Stefan Behnel

      #3
      Re: where is the Write method of ElementTree??

      gray.bowman@gma il.com wrote:
      I'm messing around with trying to write an xml file using
      xml.etree.Eleme ntTree. All the examples on the internet show the use
      of ElementTree.wri te(), although when I try to use it it's not
      available, gives me ...
      >
      ElementTree(sec tionElement).wr ite("section.xm l")
      TypeError: 'module' object is not callable
      I guess you did

      from xml.etree import ElementTree

      Then you should do this:

      ElementTree.Ele mentTree(sectio nElement).write ("section.xm l")

      sadly, the module names in ET are upper case and look like classes...

      Stefan

      Comment

      • gray.bowman@gmail.com

        #4
        Re: where is the Write method of ElementTree??

        On May 23, 3:22 am, Stefan Behnel <stefan...@behn el.dewrote:
        gray.bow...@gma il.com wrote:
        I'm messing around with trying to write an xml file using
        xml.etree.Eleme ntTree. All the examples on the internet show the use
        of ElementTree.wri te(), although when I try to use it it's not
        available, gives me ...
        >
        ElementTree(sec tionElement).wr ite("section.xm l")
        TypeError: 'module' object is not callable
        >
        I guess you did
        >
        from xml.etree import ElementTree
        >
        Then you should do this:
        >
        ElementTree.Ele mentTree(sectio nElement).write ("section.xm l")
        >
        sadly, the module names in ET are upper case and look like classes...
        >
        Stefan
        That was it! Thanks to both of you for helping.

        Comment

        Working...