Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8436379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:09:49+00:00 2026-06-10T07:09:49+00:00

Obviously , I’m new to Python. I would like to use StringIO in my

  • 0

Obviously , I’m new to Python.

I would like to use StringIO in my code below : to extract example.xml

 import os
os.chdir('d:/py/xml/')


from lxml import etree
from StringIO import StringIO

#----------------------------------------------------------------------
def parseXML(xmlFile):
    """
    Parse the xml
    """
    f = open(xmlFile)
    xml = f.read()
    f.close()

    tree = etree.parse(StringIO(xml))
    context = etree.iterparse(StringIO(xml))
    for action, elem in context:
        if not elem.text:
            text = 'None'
        else:
            text = elem.text
        print (elem.tag + ' => ' + text)

if __name__ == "__main__":

parseXML("example.xml")

But I keep getting this msg

Syntax Error: from io import import StringIO: d:\py\xml\example.py, line 621
File “d:\py\xml\example.py”, line 6, in ?
from io import import StringIO

I did google but it said to import the io model and use io.StringIO or io.BytesIO for text or Data…

Can anyone please tell me, how can I actually do that ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:09:50+00:00Added an answer on June 10, 2026 at 7:09 am

    In Python3, StringIO is in io:

    from io import StringIO
    

    (Not from io import import StringIO, the keyword import goes only once.)

    Note the the 2to3 script will do this change for you automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Obviously, I'm brand new to QTP. I use it to test an HTML page
Obviously I'm new to as3...Can someone please explain to me how I can use
Obviously new to Linux serial programming. If I use /dev/ttyS4 from minicom or termie,
I obviously don't think it would work as it is. Its more like, does
Obviously the reader doesn't like this format incoming from the response XML. Wondering if
Obviously, I'm new to iOS development, but I could really use somebody's help. I
Obviously the point of using named constants over magic numbers is for code clarity
Obviously I'd like to not have to install an Oracle client (other than simply
Obviously you dont have a mouse over effect on a touchscreen, but I would
Obviously, an index would work well if a column has a few distinct values.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.