I am trying to construct a class and call upon some functions within that class, but nothing is returned, somehting should definitely be returned

#!/usr/bin/python
import cElementTree as ET
import urllib2
import MySQLdb
print "Content-type: text/html\n"
class xml:
    @staticmethod
    
    def find_text(element):
        if element.text:
            yield element
            for subelement in element:
                for txt in find_text(subelement):
                    yield txt

    def read_xml():
        # connect
        db = MySQLdb.connect(host = "localhost", user = "adamplo1", passwd = "U7RJM5HQ", db = "adamplo1_UniProject")

        # create a database cursor
        cursor = db.cursor(MySQLdb.cursors.DictCursor)

        # execute SQL select statement
        cursor.execute("SELECT * FROM Threshold")

        Results = cursor.fetchall()
        error = " "
        feed = urllib2.urlopen("http://server-up.theatticnetwork.net/demo/")
        try:
            tree = ET.parse(feed)
		
        except Exception, inst:
            print "Unexpected error opening %s: %s" % (tree, inst)
    
        root= tree.getroot()
        text = root.getchildren()

        for item in text:
            if item.tag =="Memory":
                extra = "Memory"
            elif item.tag == "Network":
                extra = "Network"
            elif item.tag == "Vitals":
                extra = "Vitals"
            elif item.tag == "Hardware":
                extra = "Hardware"
            elif item.tag == "Swap":
                extra = "Swap"
            elif item.tag == "Swapdevices":
                extra = "Swapdevices"
            elif item.tag == "FileSystem":
                extra = "FileSystem"
            else:    
                extra = "Other"
            for element in find_text(item):
                if extra+element.tag.replace(' ','') in Results[0].keys():
                    if element.text >= Results[0][extra+element.tag.replace(' ','')]:
                        error = error + "Error with "+item.tag+" "+element.tag+" value = "+element.text +" \n"
              
                else:
                    continue
        return error


a = xml()
problem = a.read_xml()
print problem

You return the string "error". It is an empty string unless the following is true.

for element in find_text(item):
    if extra+element.tag.replace(' ','') in Results[0].keys():
        if element.text >= Results[0][extra+element.tag.replace(' ','')]:
            error = error + "Error with "+item.tag+" "+element.tag+" value = "+element.text +" \n"
              
    else:
        continue

the best debugging technique is putting print statement/function after few lines to see whether it passes a given statement

ok i have partially solved the problem and added static method bit above each function. But i am not getting the error message find_text is not defined.

How can i have class with two function in it. With on function calling on the other function within the class?

ok i was being really dumb. Solved it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.