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 8706423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:36:39+00:00 2026-06-13T03:36:39+00:00

First : am a new beg. using python..so please help me out.I’m trying to

  • 0

First : am a new beg. using python..so please help me out.I’m trying to read a XML file using Python. My xml file name is rgpost.xml

<volume name="sp" type="span" operation="create">
    <driver>HDD1</driver>
</volume>

My code :

import xml.etree.ElementTree as ET
doc = ET.parse("rgpost.xml")
s = doc.find("volume")
print s.attrib["name"]

While running this am getting error :

sp:~# python volume_check.py volume  
Traceback (most recent call last):  
  File "volume_check.py", line 13, in <module>  
    print s.attrib["name"]  
AttributeError: 'NoneType' object has no attribute 'attrib'

Thanks in advance

  • 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-13T03:36:41+00:00Added an answer on June 13, 2026 at 3:36 am

    Life is much easier if you get the root:

    >>> import xml.etree.ElementTree as ET
    >>> doc = ET.parse("rgpost.xml")
    >>> root = doc.getroot() # <--- this is the new line
    >>> root
    <Element 'volume' at 0x1004d8f10>
    >>> root.keys()
    ['operation', 'type', 'name']
    >>> root.attrib["name"]
    'sp'
    >>> root.get("name")
    'sp'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off I am still new to objective-c and still trying to learn as
I am using Xpath in Ruby with following statement. print XPath.first(Document.new(html),//tr[@id='ctl00_c1_rr_ci_trAdd']//td[2]) The Query return
I am currently trying to define my first new action in Rails 3, despite
I am trying to construct my first new action in rails, thanks to the
<root> <gallery name=First/> <gallery name=Second/> <gallery name=Third/> </root> I'm trying to rename multiple name
I've been bashing my head against trying to first divide up a file into
I'm trying to parse a xml file: <?xml version=1.0?> <settings> <output>test.dat</output> <width>5</width> <depth>4</depth> <height>10</height>
I'm trying to write code to read a binary file into a buffer, then
I'm having two DateTime -objects: $start = new DateTime('first thursday of June 2012'); $end
Consider a string array shaped like this: string[] someName = new string[] { First,

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.