473,473 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Running script in __main__ shows no output in IDLE

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")

May 22 '06 #1
5 1730
he**********@fantasy-interactive.com a écrit :
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?
I can't tell you about IDLE related stuff (I don't use it myself), but
FWIW, you have a problem with main()'s 'arg' param : you use it like this:
parser.parse(args[0]) but pass it like this: main("\\Iceman\propod\flash\xml\webService\XmlData \Authors\Heidi")


The first problem is that:
"\\Iceman\propod\flash\xml\webService\XmlData\Auth ors\Heidi"
already raises an exception ('ValueError: invalid \x escape').

The second problem is that somestring[0] returns the first characted of
somestring.

First correct your code, then see what happens. And eventually, find a
better tool than IDLE...
May 22 '06 #2
he**********@fantasy-interactive.com wrote:
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 " ....
Don't comment out those strings, you'll find them more useful in
Idle if they are there.
def main(args):
...
# 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")


As someone else said, use both a better string constant and a list,
since main looks at "args[0]".
If nothing else:

main([r"\\Iceman\propod\flash\xml\webService\XmlData\Aut hors\Heidi"])

To investigate the idle environment, simply add:

if __name__ == "__main__":
print "to main"
main([r"\\Iceman\propod\flash\xml\webService\XmlData\Aut hors\Heidi"])
else:
print 'Sorry, __name was %r, not "__main__".' % __name__
--Scott David Daniels
sc***********@acm.org
May 23 '06 #3
Thanks for your help! Shouldn't Idle have shown an error when trying to
read the string constant if it's not interpretable as a normal string,
then?

/Heidi

May 23 '06 #4
he**********@fantasy-interactive.com a écrit :
Shouldn't Idle have shown an error when trying to
read the string constant if it's not interpretable as a normal string,
then?


Yes. In my python shell, it raised an error. I don't know for sure why
this did not appear in IDLE, but there are far better tools anyway.

May 23 '06 #5
he**********@fantasy-interactive.com wrote:
Thanks for your help! Shouldn't Idle have shown an error when trying to
read the string constant if it's not interpretable as a normal string,
then?


I suspect it should. The error probably got lost in the start-script
handling somewhere.

--Scott David Daniels
sc***********@acm.org
May 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sean | last post by:
For the last couple of months I have been reading and working throught the examples in Magnus Lie Hetland's Book "Practical Python" This for all practical purposes is the first computer...
13
by: John Salerno | last post by:
If I want to write my code in a separate text editor (I like UltraEdit) but then press a single button to have that code run in the IDLE environment, is that possible? I know that you can configure...
1
by: Aaron West | last post by:
Try this script to see what queries are taking over a second. To get some real output, you need a long-running query. Here's one (estimated to take over an hour): PRINT GETDATE() select...
13
by: wattersmt | last post by:
Hello, I am trying to write a python cgi that calls a script over ssh, the problem is the script takes a very long time to execute so Apache makes the CGI time out and I never see any output. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.