Re: [Tutor] recursive problem

2010-09-11 Thread Steven D'Aprano
On Sun, 12 Sep 2010 09:03:49 am Walter Prins wrote: > So, perhaps it's an idea to call dir() on a given object and see > whether the object provides the necessary methods to function, e.g. > __iter__, __delitem__, __setitem__ and friends? There's no need to do this: attributes = dir(obj) if '__i

Re: [Tutor] recursive problem

2010-09-11 Thread Walter Prins
Just a quick contribution for what it's worth: One of the subjects being implicitly talked about here is "introspection" -- you may want to google that and see else you can find. That said, a nice article covering some of Python's introspection features is presented here on IBM's site: http://www.i

Re: [Tutor] design question

2010-09-11 Thread Albert-Jan Roskam
Hi Jan and Steven, Thanks a lot for your valuable comments. I greatly appreciate you looking into it. Steven, you recommend to <>. On one website it was mentioned that "To a young boy with a hammer, everything looks like a nail". Which meant to say that just because you CAN use a design patte

[Tutor] exceptions problem

2010-09-11 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: bgai...@gmail.com > Subject: RE: [Tutor] exceptions problem > Date: Sat, 11 Sep 2010 18:51:12 + > > > > > >> Date: Sat, 11 Sep 2010 14:43:28 -0400 >> From: bgai...@gmail.com >>

[Tutor] recursive problem

2010-09-11 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: st...@pearwood.info > Subject: RE: [Tutor] recursive problem > Date: Sat, 11 Sep 2010 18:39:31 + > > > > > >> From: st...@pearwood.info >> To: tutor@python.org >> Date: Sun, 12

Re: [Tutor] recursive problem

2010-09-11 Thread Lie Ryan
On 09/12/10 03:18, Steven D'Aprano wrote: > Or you could do this: > > if do_this_will_succeed() and do_that_will_succeed() \ > and do_something_else_will_succeed(): > do_this() > do_that() > do_something_else() > else: > do_error() > > But that hasn't done anything to prevent race

[Tutor] SOLVED: Re: Trapping HTTP Authentication Failure

2010-09-11 Thread Michael Powe
Hello, It is bloody Winblows. The script works as designed and traps the 401 exception on my slackware box ... something in the implementation of urllib2 on Windoze is broken. This has to be a known issue. Just did not see it known anywhere. Thanks. mp On Sat, Sep 11, 2010 at 02:16:07PM -040

Re: [Tutor] exceptions problem

2010-09-11 Thread bob gailer
On 9/11/2010 12:12 PM, Roelof Wobben wrote: Date: Sat, 11 Sep 2010 11:05:54 -0400 From: bgai...@gmail.com To: tutor@python.org Subject: Re: [Tutor] exceptions problem On 9/11/2010 6:56 AM, Peter Otten wrote: Steven D'Aprano wrote: On Sat, 11 Sep 20

Re: [Tutor] recursive problem

2010-09-11 Thread Steven D'Aprano
On Sun, 12 Sep 2010 04:09:20 am Roelof Wobben wrote: > > On Sun, 12 Sep 2010 03:40:38 am Roelof Wobben wrote: > >> But why is type checking then wrong. > >> Lets says I want a module who must work on strings, tuple and > >> lists. > > > > It's not *always* wrong, but let me ask you... why do you w

Re: [Tutor] recursive problem

2010-09-11 Thread Steven D'Aprano
On Sun, 12 Sep 2010 04:01:39 am Walter Prins wrote: > I guess the question to ask/consider is: How can be establish whether > a particular object supports a particular interface/set of behaviours > that we require? E.g. how do we most pythonically check whether some > object "walks like a list" a

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Michael Powe
On Sat, Sep 11, 2010 at 10:48:13AM -0400, Michael Powe wrote: > On Sat, Sep 11, 2010 at 02:25:24PM +0200, Evert Rol wrote: > > > > > >> I'm not sure what you're exactly doing here, or what you're getting, > > >> but I did get curious and dug around urllib2.py. Apparently, there is > > >> a hardc

Re: [Tutor] recursive problem

2010-09-11 Thread Roelof Wobben
> From: st...@pearwood.info > To: tutor@python.org > Date: Sun, 12 Sep 2010 04:03:43 +1000 > Subject: Re: [Tutor] recursive problem > > On Sun, 12 Sep 2010 03:40:38 am Roelof Wobben wrote: > >> But why is type checking then wrong. >> Lets says I want a mo

Re: [Tutor] recursive problem

2010-09-11 Thread Lie Ryan
On 09/12/10 04:01, Walter Prins wrote: > I guess the question to ask/consider is: How can be establish whether a > particular object supports a particular interface/set of behaviours that > we require? E.g. how do we most pythonically check whether some object > "walks like a list" and "quacks lik

Re: [Tutor] recursive problem

2010-09-11 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: wpr...@gmail.com > Subject: RE: [Tutor] recursive problem > Date: Sat, 11 Sep 2010 18:05:12 + > > > > > >> Date: Sat, 11 Sep 2010 19:01:39 +0100 >> Subject: Re: [Tutor] recursive probl

Re: [Tutor] changing list index start

2010-09-11 Thread Steven D'Aprano
On Sun, 12 Sep 2010 02:00:02 am Lie Ryan wrote: > As an alternative solution, you can derive from UserList and overload > the __getitem__ and __setitem__ operator: We've been able to inherit from list directly since at least Python 2.2. Why are you using UserList? -- Steven D'Aprano

Re: [Tutor] recursive problem

2010-09-11 Thread Steven D'Aprano
On Sun, 12 Sep 2010 03:40:38 am Roelof Wobben wrote: > But why is type checking then wrong. > Lets says I want a module who must work on strings, tuple and lists. It's not *always* wrong, but let me ask you... why do you want to *limit* the function to work on ONLY strings, tuples and lists? Th

Re: [Tutor] recursive problem

2010-09-11 Thread Walter Prins
> That's the whole point! You don't WANT to know what type it is. You want to > just use it how you want, an if it behaves properly, who cares what type it > is? > > See when you type check you are forcing the user to use those types. What > if they want to derive a subclass from list? Is there rea

Re: [Tutor] exceptions problem

2010-09-11 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Hello Bob, Oke, I try to fish. When I do x="a" y=nt(x) Then I get ValueError. When I do x= 1.2 y=int(x) No exception is raised. But when I do then x = I get a false. When I now do float(x) - int(x) I get 1.2 - 1 =.2 and that's greater then 0 Because one

Re: [Tutor] recursive problem

2010-09-11 Thread Luke Paireepinart
On Sep 11, 2010, at 12:40 PM, Roelof Wobben wrote: > > > > >> From: st...@pearwood.info >> To: tutor@python.org >> Date: Sun, 12 Sep 2010 03:27:42 +1000 >> Subject: Re: [Tutor] recursive problem >> >> On Sun, 12 Sep 2010 03:18:19 am Steven D'Aprano wr

Re: [Tutor] recursive problem

2010-09-11 Thread Roelof Wobben
> From: st...@pearwood.info > To: tutor@python.org > Date: Sun, 12 Sep 2010 03:27:42 +1000 > Subject: Re: [Tutor] recursive problem > > On Sun, 12 Sep 2010 03:18:19 am Steven D'Aprano wrote: > >> But that hasn't done anything to prevent race conditions. S

Re: [Tutor] recursive problem

2010-09-11 Thread Steven D'Aprano
On Sun, 12 Sep 2010 03:18:19 am Steven D'Aprano wrote: > But that hasn't done anything to prevent race conditions. So the real > reason people use LBYL is that they're too lazy to write hideously > ugly, but reliable, code, and they're just hoping that they will > never expose the race condition.

Re: [Tutor] recursive problem

2010-09-11 Thread Roelof Wobben
> From: st...@pearwood.info > To: tutor@python.org > Date: Sun, 12 Sep 2010 03:18:19 +1000 > Subject: Re: [Tutor] recursive problem > > On Fri, 10 Sep 2010 09:30:23 pm Ewald Horn wrote: > >> While EAFP is great, it's not >> always the best way to proceed.

Re: [Tutor] recursive problem

2010-09-11 Thread Steven D'Aprano
On Fri, 10 Sep 2010 09:30:23 pm Ewald Horn wrote: > While EAFP is great, it's not > always the best way to proceed. That, at least, is correct. But what you say next is not: > Sometimes you want programs to be > very robust and secure, this is where LBYL comes in - it is quite > often used in

Re: [Tutor] exceptions problem

2010-09-11 Thread Roelof Wobben
> Date: Sat, 11 Sep 2010 11:05:54 -0400 > From: bgai...@gmail.com > To: tutor@python.org > Subject: Re: [Tutor] exceptions problem > > On 9/11/2010 6:56 AM, Peter Otten wrote: >> Steven D'Aprano wrote: >> >>> On Sat, 11 Sep 2010 09:56:41 am bob gailer wro

Re: [Tutor] changing list index start

2010-09-11 Thread Rance Hall
On Sat, Sep 11, 2010 at 10:40 AM, Joel Goldstick wrote: > > I think the first message in the original post is instructive: > > "I'm using the following function style I found on the net to create > menus for a command line python script:" > > I (sometimes!) love looking at other peoples code to

Re: [Tutor] changing list index start

2010-09-11 Thread Lie Ryan
On 09/11/10 23:25, Rance Hall wrote: > On Fri, Sep 10, 2010 at 6:14 PM, Lie Ryan wrote: >> On 09/11/10 07:36, Rance Hall wrote: > > > >> In most cases in Python, you would almost never need to reference the >> list's index directly since python makes it easy to use iterators; >> however in your

Re: [Tutor] changing list index start

2010-09-11 Thread Joel Goldstick
On Sat, Sep 11, 2010 at 11:15 AM, Steven D'Aprano wrote: > On Sat, 11 Sep 2010 11:25:12 pm Rance Hall wrote: > > > Thanks everyone for responding, Because this menu structure is > > repeated many times in my code, the ideal solution would have been to > > "set index start = 1" in the beginning of

Re: [Tutor] changing list index start

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 11:25:12 pm Rance Hall wrote: > Thanks everyone for responding, Because this menu structure is > repeated many times in my code, the ideal solution would have been to > "set index start = 1" in the beginning of the script. That is exactly the wrong solution. That will break a

Re: [Tutor] exceptions problem

2010-09-11 Thread bob gailer
On 9/11/2010 6:56 AM, Peter Otten wrote: Steven D'Aprano wrote: On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: I never thought that you can use a float and a integer to look if the number is a integer. You can't. I made that comment in the context of the OPs function: def readposint()

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Michael Powe
On Sat, Sep 11, 2010 at 02:25:24PM +0200, Evert Rol wrote: > > >> I'm not sure what you're exactly doing here, or what you're getting, > >> but I did get curious and dug around urllib2.py. Apparently, there is > >> a hardcoded 5 retries before the authentication really fails. So any > >> stack t

Re: [Tutor] changing list index start

2010-09-11 Thread Knacktus
Am 11.09.2010 15:46, schrieb Joel Goldstick: On Sat, Sep 11, 2010 at 9:25 AM, Rance Hall mailto:ran...@gmail.com>> wrote: On Fri, Sep 10, 2010 at 6:14 PM, Lie Ryan mailto:lie.1...@gmail.com>> wrote: > On 09/11/10 07:36, Rance Hall wrote: > In most cases in Python, you woul

Re: [Tutor] changing list index start

2010-09-11 Thread Joel Goldstick
On Sat, Sep 11, 2010 at 9:25 AM, Rance Hall wrote: > On Fri, Sep 10, 2010 at 6:14 PM, Lie Ryan wrote: > > On 09/11/10 07:36, Rance Hall wrote: > > > > > In most cases in Python, you would almost never need to reference the > > list's index directly since python makes it easy to use iterators; >

Re: [Tutor] changing list index start

2010-09-11 Thread Rance Hall
On Fri, Sep 10, 2010 at 6:14 PM, Lie Ryan wrote: > On 09/11/10 07:36, Rance Hall wrote: > In most cases in Python, you would almost never need to reference the > list's index directly since python makes it easy to use iterators; > however in your particular case, which is a valid exception, enu

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Evert Rol
>> I'm not sure what you're exactly doing here, or what you're getting, >> but I did get curious and dug around urllib2.py. Apparently, there is >> a hardcoded 5 retries before the authentication really fails. So any >> stack trace would be the normal stack trace times 5. Not the 30 you >> mentio

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Michael Powe
On Sat, Sep 11, 2010 at 01:09:31PM +0200, Evert Rol wrote: > >>> My script to call a web service authenticates. > > > >> Sorry, but where is the (full) script? I missed an attachment or > >> (preferably) a link. > > > > Hello, > > > > Sorry, the verb of the sentence is "authenticates," as i

Re: [Tutor] smtp connection problem --- socket error 10061

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 04:09:20 am goodh...@gmail.com wrote: > I could not connect with gmail smtp server in Vista 32( worked ok > in XP 32). Both vista and xp have same anti-virus software. > > >>> smtplib.SMTP("smtp.gmail.com",587) > > Traceback (most recent call last): >File "", line 1, in >

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Evert Rol
>>> My script to call a web service authenticates. > >> Sorry, but where is the (full) script? I missed an attachment or >> (preferably) a link. > > Hello, > > Sorry, the verb of the sentence is "authenticates," as in, "My script > ... authenticates." Sorry, misread that. Although code does

Re: [Tutor] hashlib problems

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 06:54:39 am Rance Hall wrote: > I will apologize for the tone and using the word "bug" without > sufficient evidence, and I will be more thorough in the future. Using the word "bug" itself isn't the problem. Nor is it that you made a mistake -- we've all done that. A few days

Re: [Tutor] changing list index start

2010-09-11 Thread Francesco Loffredo
On 10/09/2010 23.36, Rance Hall wrote: I'm using the following function style I found on the net to create menus for a command line python script: def mainmenu(): # the main menu todolist() mainmenuoptions = ['Clients','Jobs','Billing','Quotes','To Do Items','Employee','Exit']

Re: [Tutor] exceptions problem

2010-09-11 Thread Peter Otten
Steven D'Aprano wrote: > On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: >> > I never thought that you can use a float and a integer to look if >> > the number is a integer. >> >> You can't. > > What? Of course you can. > > def is_integer(x): > """Return True if x is an integer.""" > t

Re: [Tutor] exceptions problem

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 09:56:41 am bob gailer wrote: > > I never thought that you can use a float and a integer to look if > > the number is a integer. > > You can't. What? Of course you can. def is_integer(x): """Return True if x is an integer.""" try: return 1.0*x == int(x) exc

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 12:35:48 am Huy Ton That wrote: > I am reading the decorator section within Expert Python Programming > and I am very confused in the first example, of a method that was > done before decorators. It reads: > > class WhatFor(object): > def it(cls): > print 'work with

Re: [Tutor] Exception Handling and Stack traces

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 04:47:13 am Michael Powe wrote: > No problem, I am working on getting this sorted out. The > documentation seems to be written as reminder for people who already > know how this stuff works, rather than as a clear explanation for > anybody working with it. That's because the

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Michael Powe
On Sat, Sep 11, 2010 at 01:28:26AM +0200, Evert Rol wrote: > > My script to call a web service authenticates. > Sorry, but where is the (full) script? I missed an attachment or (preferably) > a link. Hello, Sorry, the verb of the sentence is "authenticates," as in, "My script ... authentica

Re: [Tutor] exceptions problem

2010-09-11 Thread Francesco Loffredo
On 11/09/2010 1.56, bob gailer wrote: On 9/10/2010 2:48 PM, Roelof Wobben wrote: Date: Fri, 10 Sep 2010 20:23:09 +0200 From: f...@libero.it To: tutor@python.org Subject: Re: [Tutor] exceptions problem ... > ... > Roelof Francesco Thank you. I never thought that you can use a float and a int

Re: [Tutor] What Design Pattern for Document class (NOT URGENT)

2010-09-11 Thread Knacktus
Hi Karim, it's difficult to comment as to me the problem is not quite clear. But I try ;-) You have a complex xml and need to read different data types. For each type you have certain rules, how to extract them from the xml (docrules). You could create a DocRule class, that do nothing but hol

Re: [Tutor] design question

2010-09-11 Thread Steven D'Aprano
On Sat, 11 Sep 2010 12:11:37 am Albert-Jan Roskam wrote: > Inside my program I have to keep a list of all the image files that > are scheduled for data entry. Sounds like you need to keep a list of all the image files that are scheduled for data entry then. > The main purpose is to be able to

Re: [Tutor] design question

2010-09-11 Thread Knacktus
Am 10.09.2010 16:11, schrieb Albert-Jan Roskam: Hi Jan, Here's a screendump of my program: http://nl.tinypic.com/r/2qtlojc/7 . This might make my description a little bit clearer. The beautiful sunset will in reality be a dull, handwritten form. ;-) Regarding the iterator pattern, I was referri