Running script in __main__ shows no output in IDLE
heidi.hunter at fantasy-interactive.com
heidi.hunter at fantasy-interactive.com
Mon May 22 08:26:41 EDT 2006
I just downloaded the most recent (2.4.3) Python and IDLE (1.1.3) to
Windows XP Professional. I'm new to the IDLE environment, so hopefully
someone can tell me what I'm missing here! Below is the code, which I'm
editing within IDLE, and attempting to test with the Run commands.
I was expecting to see at least see the prints to stdout from the if
__name__ ... statement and main() function, but when I use F5 Run
module I don't see any output or errors. Any suggestions? Does IDLE
still need the executable file statement at the top even if I run it
explicity?
---------------------------------------------------------------------------------------
import sys
from xml.sax import ContentHandler, make_parser
from xml.sax.handler import feature_namespaces
class AuthorHandler(ContentHandler):
# """Converts an author file"""
def __init__(self,outfilename):
# """Constructor. Takes output file name."""
self.outfile = ""
self.insertCmd = "INSERT Authors SET "
def startElement(self,name,attrs):
# """Overridden. Creates SQL statements from author nodes."""
if name != "root":
self.insertCmd += "%s = '" % self.convertColumnName(name)
def characters(self,chars):
# """Overridden. Add tag values as column values."""
self.insertCmd += chars
def endElement(self,name):
# """Overridden. Close column value and add separator."""
if name == "root":
self.insertCmd += "';"
else:
self.insertCmd += "',"
def convertColumnName(self,name):
return name
def main(args):
print "In main"
# Create an instance of the handler classes
ah = AuthorHandler()
# Create an XML parser
parser = make_parser()
# Tell the parser to use your handler instance
parser.setContentHandler(ah)
# Parse the file; your handler's methods will get called
parser.parse(args[0])
print ah.insertCmd
if __name__ == "__main__":
print "to main"
main("\\Iceman\propod\flash\xml\webService\XmlData\Authors\Heidi")
More information about the Python-list
mailing list