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/" 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
8,018 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,770 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, 2022 in Python by Kichu
• 19,040 points
1,379 views
0 votes
1 answer

Python Math - TypeError: 'NoneType' object is not subscriptable

“TypeError: 'NoneType' object is not subscriptable” is ...READ MORE

answered Jan 4, 2023 in Python by Elton
• 400 points
1,016 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,020 points
2,950 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,220 points
29,197 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
5,904 views
0 votes
0 answers

TypeError: 'list' object is not callable in python

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

Feb 3, 2022 in Python by Nandini
• 5,480 points
1,036 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, 2022 in Python by Rahul
• 9,680 points
1,944 views
0 votes
1 answer

Error: 'int' object is not subscriptable - Python

The issue is in the line: int([x[age1]]) The solution ...READ MORE

answered Apr 30, 2022 in Python by narikkadan
• 63,600 points
1,603 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
35,697 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP