| | |
Python Class
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
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,071
Reputation:
Solved Threads: 299
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
Views: 483 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced anydbm app bash beginner bits calling chmod cmd code data dictionary directory dynamic edit examples excel external feet file float format ftp function gui homework http i/o images import info input ip itunes java keycontrol line linux list lists loan loop maintain millimeter mouse newb number numbers output panel parsing path port prime print program programming projects push py-mailer py2exe pygame pyqt python queue random rational recursion recursive scrolledtext smtp split ssh string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable variables ventrilo web webservice whileloop windows wxpython xlib






