TypeError Element object is not subscriptable

0 votes

HI, It's 2 Am i am asking this question, 

i  have xml file which is very huge, i wanted to fetch particular value from the tag which i shown below. 

i wanted to fetch the   <name>1.Start Up</name> from the below xml. kindly help me with exact python code.

i was using 

from xml.dom import minidom

etree=minidom.parse('.\\BuildRelease.xml')

sheets=etree.getElementsByTagName("subsheet")

print(sheets[0].firstchild.data)

-<process xmlns="http://www.blueprism.co.uk/product/process" name="WW Process 3 (Query Regional Catalogue)" id="d15c64dd-1644-45b2-a3dd-8e584d379669">


-<process name="WW Process 3 (Query Regional Catalogue)" byrefcollection="true" narrative="Searches for items not added in the WW catalogue and adds them on Mondays and Tuesdays" bpversion="6.6.0.15260" version="1.0">

+<view>

<preconditions/>

<endpoint narrative=""/>

-<subsheet published="False" type="Normal" subsheetid="a6eff02a-a8f5-49bb-bb20-d4216b513122">

       <name>1.Start Up</name>

+<view>

</subsheet


 

Feb 18, 2020 in Python by Bharati
• 120 points
5,746 views

1 answer to this question.

0 votes

Hey Bharti,

You can get some idea from the below example. 

  • This mainly happens with functions return different data types according to the parameters given. The best way to avoid this is to use type() function to determine the return value’s data type and act accordingly


  1. x = fun() #function whose return data type is unknown
  2. if type(x) == int:#if the return value is an integer
  3. #do this
  4. elif type(x) == str:#if the return value is a string
  5. #do this

If the error has occurred inside the function you need to check your code to ensure it’s working properly.

More about non-subscriptable error (TypeError)

Python will throw a TypeError if you try to access a non-subscriptable in a way that you access a string or array object (or any other type of subscriptable object) .

Here a string object subscripted



  1. >>> x = 'this is subscriptable'
  2. >>> x[0]
  3. >>> 't'

Some common non-subscriptable object types are int, float, bool and None



  1. >>> y = 123 #an integer
  2. >>> y[0] # will result an error
  3. Traceback (most recent call last):
  4. File "<pyshell#29>", line 1, in <module>
  5. y[0]
  6. TypeError: 'int' object is not subscriptable
  7. >>>

This type of errors happen when you use the same variable to store different type of data types throughout your code and you eventually lost track of the data type the variable currently has.

The solution is either to check the variable carefully throughout the code or to use different variables to store values with different data types if memory usage is not an issue.

Example:



  1. >>> x = '10' #x is a string
  2. >>> print(x)
  3. 10
  4. >>> x = int(x) #x is now a int
  5. >>> print(x)
  6. 10
  7. >>> x[0] # will result an error
  8. Traceback (most recent call last):
  9. File "<pyshell#29>", line 1, in <module>
  10. y[0]
  11. TypeError: 'int' object is not subscriptable
  12. >>>
answered Feb 18, 2020 by Gitika
• 65,850 points

Related Questions In Python

0 votes
0 answers

TypeError: 'type' object is not subscriptable when indexing in to a dictionary

I use dict to shorten things as ...READ MORE

May 24 in Python by Kichu
• 19,040 points
85 views
0 votes
1 answer

print(instance(0).id) TypeError: 'list' object is not callable

Hey @Suraj, For me its working fine. ...READ MORE

answered Jan 18, 2019 in Python by Priyaj
• 58,080 points
1,461 views
0 votes
1 answer

Python TypeError: 'list' object is not callable.

The error says the list is not ...READ MORE

answered Feb 9, 2019 in Python by Omkar
• 69,210 points
27,634 views
0 votes
1 answer

i am normalizing the data set iris in python and get the error ::TypeError: 'numpy.float64' object is not callable

TRY THIS   #Nomalisation for i in names:     print(i)   ...READ MORE

answered Aug 20, 2019 in Python by Noel Deepak Palle
4,888 views
0 votes
0 answers

TypeError: 'list' object is not callable in python

I am a beginner in Python, created ...READ MORE

Feb 3 in Python by Nandini
• 5,480 points
44 views
0 votes
1 answer

TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3

After what I observed, you would have ...READ MORE

answered Feb 11 in Python by Rahul
• 8,980 points
142 views
0 votes
0 answers

Error: 'int' object is not subscriptable - Python

I was trying a program in which ...READ MORE

Apr 29 in Python by Kichu
• 19,040 points
259 views
0 votes
0 answers

TypeError: 'NoneType' object is not iterable in Python

What does this error mean?  I get this ...READ MORE

May 5 in Python by Kichu
• 19,040 points
105 views
0 votes
3 answers

TypeError: 'module' object is not callable

Solve By Calling with Module Name Another solution to the TypeError: 'module' object ...READ MORE

answered Jan 4, 2021 in Python by Carlos
20,155 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP