| | |
Python Class
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 58
Reputation:
Solved Threads: 0
I am trying to construct a class and call upon some functions within that class, but nothing is returned, somehting should definitely be returned
Python Syntax (Toggle Plain Text)
#!/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
Last edited by adam291086; Jan 22nd, 2009 at 12:57 pm.
•
•
Join Date: Dec 2006
Posts: 1,017
Reputation:
Solved Threads: 286
You return the string "error". It is an empty string unless the following is true.
Python Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- Starting Python (Python)
- Python class object - another strange behaviour (Python)
- make a copy of python class (Python)
- Comparing Python and C, Part 10, Structures (Python)
- Why use a Python class? (Python)
- a class question (Python)
Other Threads in the Python Forum
- Previous Thread: Web Spider?
- Next Thread: tkinter
| Thread Tools | Search this Thread |
abrupt ansi anti apache application approximation array backend beginner binary book builtin calculator converter countpasswordentry curved dan08 dictionaries dictionary dynamic edit examples file float format function gui heads homework import inches input java launcher library line lines linux list lists loop mouse movingimageswithpygame mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pysimplewizard python random recursion redirect remote reverse scrolledtext session simple smtp software statictext statistics string strings syntax table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






