[Tutor] Exceptions vs. Status Codes

2005-12-06 Thread wkranec
Hi, I have a general question regarding programming style which may or may not have an answer. Is it a better practice to have a function raise an exception on error, so that the error can be caught; or return a status code indicating that the function was unsuccessful? Like I said, I don't expe

Re: [Tutor] Read XML

2005-12-06 Thread Kent Johnson
Joseph Quigley wrote: > How do I read xml? The python documentation doesn't help me. > Or, how can I remove the (tags?) ? If you want to strip out all the tags and just leave the text, Strip-o-Gram might do it. http://www.zope.org/Members/chrisw/StripOGram There was a thread here recently about

Re: [Tutor] Timer

2005-12-06 Thread Liam Clarke-Hutchinson
Hi, time.sleep() takes an argument as seconds. Regards, Liam Clarke -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bob Sent: Wednesday, 7 December 2005 3:59 p.m. To: Joseph Quigley; tutor@python.org Subject: Re: [Tutor] Timer At 06:57 AM 12/6/2005

Re: [Tutor] Timer

2005-12-06 Thread bob
At 06:57 AM 12/6/2005, Joseph Quigley wrote: >I'd like to make a 30 minute timer. How an I do that? With time? import time time.sleep(30) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Read XML

2005-12-06 Thread Danny Yoo
On Tue, 6 Dec 2005, Joseph Quigley wrote: > How do I read xml? The python documentation doesn't help me. Or, how can > I remove the (tags?) ? Hi Joseph, The modules in the standard library for XML reading should be functional. For example, here is some 'xml.dom.minidom' example code to show h

[Tutor] Read XML

2005-12-06 Thread Joseph Quigley
How do I read xml? The python documentation doesn't help me. Or, how can I remove the (tags?) ? thanks, Joe-- There are 10 different types of people in the world.Those who understand binary and those who don't. ___ Tutor maillist - Tutor@python.org http

Re: [Tutor] Python Script Problem. Simple sql problem & py problems.

2005-12-06 Thread w chun
> I wrote my first script (ever) in Python. > : > The second one is more python specific I guess. The programs prints > the "Exiting" string on exit one time for every action I do. Which > means that if I add 4 users, I'll see 4 time exiting printed. If I add > 2 users and delete 1 us

Re: [Tutor] smtplib mail header problem

2005-12-06 Thread Liam Clarke-Hutchinson
Okay, just checked the docs - "sendmail( from_addr, to_addrs, msg[, mail_options, rcpt_options]) Note: The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents. The SMTP does not modify the message headers in any way." So my guess is that th

Re: [Tutor] whats the best command to end a program

2005-12-06 Thread Joseph Quigley
    if int(time.strftime(%H)) > 4:some end the program command else:continuewhat would be best used here ? I would use raise SystemExit But another possibility is: import sys then to exit sys.exit()-- There are 10 different types of people in the world.T

Re: [Tutor] whats the best command to end a program

2005-12-06 Thread nephish
right, greater > 16 was what i ment. he he it is not a gui. is raise SystemExit built in ? thanks gents sk On Tue, 2005-12-06 at 21:49 +, Alan Gauld wrote: > > what would be the best command to end a program with. > > If its Tkinter (or another GuI) there will be a quit command > somewhe

Re: [Tutor] smtplib mail header problem

2005-12-06 Thread dave s
On Tuesday 06 December 2005 21:13, Liam Clarke-Hutchinson wrote: > Hi Dave, > > IIRC The first argument to sendmail() is the name of the account that's > sending... So when you include your subject there, it seems your ISP is > somewhat forgiving. > > Liam Clarke-Hutchinson| Contact Centre Advisor|

Re: [Tutor] whats the best command to end a program

2005-12-06 Thread Alan Gauld
> what would be the best command to end a program with. If its Tkinter (or another GuI) there will be a quit command somewhere. Call that to ensure that the GUI framework gets tidied up properly. For normal programs import sys; sys.exit() You can pass an exit code to the outdside world as a

Re: [Tutor] How to Pass lists by value

2005-12-06 Thread w chun
On 12/6/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > Lots of good stuff from Wes snipped... > > (a side note here: that only mutable objects have methods.) > > But this is not quite true. Strings are immutable and have lots > of methods and even tuples and plain integers have methods oh POO. i *

Re: [Tutor] smtplib mail header problem

2005-12-06 Thread Liam Clarke-Hutchinson
Hi Dave, IIRC The first argument to sendmail() is the name of the account that's sending... So when you include your subject there, it seems your ISP is somewhat forgiving. Liam Clarke-Hutchinson| Contact Centre Advisor| Ministry of Economic Development DDI +64 3 962 2639 | Fax +64 3 962 6220 w

[Tutor] smtplib mail header problem

2005-12-06 Thread dave s
Hi all, I have a python script that works out & emails my employer with parts that I have used. It has been great for 11ish months, now all my mail is classed as spam & junked :( Apparently the reason for it being junked is ... 'No subject' and 'No Sender' I set up a small test script to isol

Re: [Tutor] How to Pass lists by value

2005-12-06 Thread Alan Gauld
Lots of good stuff from Wes snipped... > (a side note here: that only mutable objects have methods.) But this is not quite true. Strings are immutable and have lots of methods and even tuples and plain integers have methods (albeit Pythons magic operator methods) which can be subclassed and o

Re: [Tutor] Auto package install?

2005-12-06 Thread python-tutor
Scott, Take a look at setuptools: http://peak.telecommunity.com/DevCenter/setuptools It should handle everything you are looking for with ease. Turbogears ( http://turbogears.org )is a real world project that uses it. So far it seems to be flexible and reliabe for me. Good Luck, --Todd Ma

Re: [Tutor] How to Pass lists by value

2005-12-06 Thread Hans Dushanthakumar
Thanks for your valuable feedback guys. Cheers Hans -Original Message- From: w chun [mailto:[EMAIL PROTECTED] Sent: Tuesday, 6 December 2005 9:11 p.m. To: Hans Dushanthakumar Cc: tutor@python.org Subject: Re: How to Pass lists by value On 12/5/05, Kent Johnson <[EMAIL PROTECTED]> wrote

Re: [Tutor] Displaying Separate Tables for Specific Dictionary Keys

2005-12-06 Thread Kent Johnson
KJZZ Webmaster wrote: > I have a list of dictionaries. Each dictionary has a key named "program". > > I can display a html table for the entire list of dictionaries, however... > > I would like to display distinct html tables for each program while also > displaying the playlist for the day in c

[Tutor] whats the best command to end a program

2005-12-06 Thread nephish
Hey there, what would be the best command to end a program with. i have an app that i want to start every day at 6am from cron but i want it to shutdown at 4pm i was going to check by time on every loop if int(time.strftime(%H)) > 4: some en

[Tutor] Auto package install?

2005-12-06 Thread Nelson, Scott
The Zen of Python (http://www.python.org/doc/Humor.html#zen) states: "There should be one-- and preferably only one --obvious way to do it."   I'm searching for the obvious Pythonic way to achieve automated package installation (I believe Perl's CPAN can be used to accomplish this in Per

Re: [Tutor] Exception repeated in a loop

2005-12-06 Thread Jan Eden
Kent Johnson wrote on 06.12.2005: >The parser processes up to the error. It never recovers from the >error. HTMLParser has an internal buffer and buffer pointer that is >never advanced when an error is detected; each time you call feed() >it tries to parse the remaining data and gets the same erro

[Tutor] Displaying Separate Tables for Specific Dictionary Keys

2005-12-06 Thread KJZZ Webmaster
I have a list of dictionaries. Each dictionary has a key named "program". I can display a html table for the entire list of dictionaries, however... I would like to display distinct html tables for each program while also displaying the playlist for the day in chronological order (the list has a

Re: [Tutor] Exception repeated in a loop

2005-12-06 Thread Jan Eden
Hi, Nelson, Scott wrote on 06.12.2005: >An unhandled exception immediately stops the execution of your code. > >A handled exception (try/except) does not stop code execution (unless >you explicitly tell it to). > >This shows how a handled exception does not stop code execution: > >try: > raise

Re: [Tutor] Exception repeated in a loop

2005-12-06 Thread Kent Johnson
Jan Eden wrote: >Hi, > >I use the following loop to parse some HTML code: > >for record in data: >try: >parser.feed(record['content']) >except HTMLParseError, (msg): >print "!!!Parsing error in", record['page_id'], ": ", msg > >Now after HTMLParser encounters a parse error

[Tutor] Python Script Problem. Simple sql problem & py problems.

2005-12-06 Thread Panagiotis Atmatzidis
Hello, I wrote my first script (ever) in Python. It's an interface for handling the proftpd virtual users. I wrote the script after reading the howto. You can see the browse[1] the code anytime. These are my first steps in programming in general so.. the problems that this script has until now, a

Re: [Tutor] Exception repeated in a loop

2005-12-06 Thread Nelson, Scott
An unhandled exception immediately stops the execution of your code. A handled exception (try/except) does not stop code execution (unless you explicitly tell it to). This shows how a handled exception does not stop code execution: try: raise Exception except: print 'caught excep

Re: [Tutor] Timer

2005-12-06 Thread Joseph Quigley
Sorry, this is a little console project to tell me when there new headlines on slashdot.org using their rss file. All it does is see if there's something different and if there is it will tell you. Here's my timer: while True:     if count > 1800:     break     time.sleep(1)   

Re: [Tutor] Exception repeated in a loop

2005-12-06 Thread Jan Eden
Hi Pawel, Pawel Kraszewski wrote on 06.12.2005: >Dnia wtorek, 6 grudnia 2005 16:29, Jan Eden napisa?: >> Hi, >> >> I use the following loop to parse some HTML code: >> >> for record in data: >> try: >> parser.feed(record['content']) >> except HTMLParseError, (msg): >> prin

Re: [Tutor] Exception repeated in a loop

2005-12-06 Thread Pawel Kraszewski
Dnia wtorek, 6 grudnia 2005 16:29, Jan Eden napisał: > Hi, > > I use the following loop to parse some HTML code: > > for record in data: > try: > parser.feed(record['content']) > except HTMLParseError, (msg): > print "!!!Parsing error in", record['page_id'], ": ", msg > > No

Re: [Tutor] MS ODBC

2005-12-06 Thread bob
At 09:57 PM 12/5/2005, Gregorius Gede Wiranarada wrote: >hello, >how can i connect python to read data from ms access or ms foxpro? foxpro: Install (if you have not) Mark Hammond's pywin32 to get the odbc module http://sourceforge.net/project/showfiles.php?group_id=78018 Create a Data Source (if

[Tutor] Exception repeated in a loop

2005-12-06 Thread Jan Eden
Hi, I use the following loop to parse some HTML code: for record in data: try: parser.feed(record['content']) except HTMLParseError, (msg): print "!!!Parsing error in", record['page_id'], ": ", msg Now after HTMLParser encounters a parse error in one record, it repeats to

Re: [Tutor] Timer

2005-12-06 Thread Joseph Quigley
thanks. I'm also trying time.time() I hope one works. One disadvantage though, now that i think of it is that time.sleep() freezes everything and I don't think I want that but I'll try it anyway.On 12/6/05, Pujo Aji <[EMAIL PROTECTED] > wrote:Probably the simplest thing is to make the computer slee

Re: [Tutor] Timer

2005-12-06 Thread Kent Johnson
Joseph Quigley wrote: > I'd like to make a 30 minute timer. How an I do that? With time? A little context would be helpful. If you are writing a standalone app that just needs to wait 30 minutes, then do something, use time.sleep(). If the program needs to be able to do something else at the sa

Re: [Tutor] Timer

2005-12-06 Thread Pujo Aji
Probably the simplest thing is to make the computer sleep in a specific time.Example:def main():    time.sleep(2) # sleeping 2 second    print 'finish'Cheers,pujo On 12/6/05, Joseph Quigley <[EMAIL PROTECTED]> wrote: I'd like to make a 30 minute timer. How an I do that? With time? Thanks,    Joe--

[Tutor] Timer

2005-12-06 Thread Joseph Quigley
I'd like to make a 30 minute timer. How an I do that? With time? Thanks,    Joe-- There are 10 different types of people in the world.Those who understand binary and those who don't. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/l

Re: [Tutor] terminology

2005-12-06 Thread david
thanks for tries and bisect. this led me to the wikipedia article http://en.wikipedia.org/wiki/Search_algorithm which was where i was looking to start. so, i think the simplest approach to search through a short list would be a brute force algorithm. like so :   get a letter and compare it to

Re: [Tutor] MS ODBC

2005-12-06 Thread Kent Johnson
Gregorius Gede Wiranarada wrote: >hello, >how can i connect python to read data from ms access or ms foxpro? > I don't know about FoxPro. You can connect to MS Access from a Windows client using adodbapi (free) http://adodbapi.sourceforge.net/ eGenix mxODBC (commercial) http://www.egenix.com/fil

Re: [Tutor] How to Pass lists by value

2005-12-06 Thread w chun
On 12/5/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > > You have to change how you think about variables. In Python, a variable > is not a storage location into which values are put, it is a reference > to an object - a name given to an object. Assignment binds a name to a > value. > > When you cal