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") 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... 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
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 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. 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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. ...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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,...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |