| | |
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,045
Reputation:
Solved Threads: 294
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 approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog decimals dictionaries dictionary directory drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable ventrilo wikipedia windows write wxpython xlib






