Re: [Tutor] Validation loop

2008-09-13 Thread bob gailer
Norman Khine wrote: Hello, I am writting a little module that validates if a member has completed all the previous exams before they can access the current exam. The way, I thought it may work is to: Search all previous exams from the previous topics and check to see if the user has passed t

[Tutor] Validation loop

2008-09-13 Thread Norman Khine
Hello, I am writting a little module that validates if a member has completed all the previous exams before they can access the current exam. The way, I thought it may work is to: Search all previous exams from the previous topics and check to see if the user has passed them, if not, then the

Re: [Tutor] validation

2007-08-28 Thread Terry Carroll
On Tue, 28 Aug 2007, Kent Johnson wrote: > Terry Carroll wrote: > > > 1A) a variation of option 1 (which is why I said "depending on how you > > count" above): duck-typing with error recovery. > > > > def incr(n): > > "returns an incremented value of n, or None if n is not incrementable" > >

Re: [Tutor] validation

2007-08-28 Thread Kent Johnson
Terry Carroll wrote: > 1A) a variation of option 1 (which is why I said "depending on how you > count" above): duck-typing with error recovery. > > def incr(n): > "returns an incremented value of n, or None if n is not incrementable" > try: > return n + 1 > except: > return None >

Re: [Tutor] validation

2007-08-28 Thread Terry Carroll
On Tue, 28 Aug 2007, Michael wrote: > I now have several methods in my arsenal and they all look quite simple, > now that I know. Just wondering, when would you use isInstance()? Well, as this thread has shown, I'm no expert, but let me take a stab on it. If nothing else, we'll all learn somet

Re: [Tutor] validation

2007-08-28 Thread Michael
Thanks Everybody I now have several methods in my arsenal and they all look quite simple, now that I know. Just wondering, when would you use isInstance()? Thanks Alan Gauld wrote: > "Michael" <[EMAIL PROTECTED]> wrote > > >> to check and make sure that an integer is entered and the program

Re: [Tutor] validation

2007-08-27 Thread Terry Carroll
On Mon, 27 Aug 2007, Kent Johnson wrote: > isinstance can take a tuple of types as its second argument > > Note that >isinstance(thing, (list, tuple)) > > and >type(thing) in [list, tuple] > > are not equivalent. The first will be true for objects whose type is a > subclass of list

Re: [Tutor] validation

2007-08-27 Thread Kent Johnson
Terry Carroll wrote: > I ended up writing a short isListOrTuple function that went something > like this: > > def isListOrTuple(thing): > result = False > if isinstance(thing, list): result = True > if isinstance(thing, tuple): result = True > return result isinstance can take a tuple o

Re: [Tutor] validation

2007-08-27 Thread Terry Carroll
On Mon, 27 Aug 2007, Kent Johnson wrote: > For the built-in types, since Python 2.2 the familiar name (int, str, > float, list, dict, set) *is* the type and you can compare to that > directly, e.g.: > > In [13]: type(3)==int > Out[13]: True > In [14]: type([]) == list > Out[14]: True That is s

Re: [Tutor] validation

2007-08-27 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote >> if type(x) == type(int()): >> > For the built-in types, since Python 2.2 the familiar name (int, > str, > float, list, dict, set) *is* the type and you can compare to that > directly, e.g.: > > In [13]: type(3)==int > Out[13]: True I knew I should be

Re: [Tutor] validation

2007-08-27 Thread Kent Johnson
Alan Gauld wrote: > "Michael" <[EMAIL PROTECTED]> wrote >> trying to use the Type() function but I cannot work out how to check >> the >> return value? Caomparing it to 'int' or 'str' isn't working, > > The easiest way is to compare to another type: > > x = 42 > if type(x) == type(int()): > > o

Re: [Tutor] validation

2007-08-27 Thread Alan Gauld
"Michael" <[EMAIL PROTECTED]> wrote > to check and make sure that an integer is entered and the program > not > crashing when a naughty user enters a character instead. John F has already pointed you to the use of try/except for this, however... > trying to use the Type() function but I cannot

Re: [Tutor] validation

2007-08-27 Thread John Fouhy
On 27/08/07, Michael <[EMAIL PROTECTED]> wrote: > I am fairly new to Python and I wish to validate input. Such as wanting > to check and make sure that an integer is entered and the program not > crashing when a naughty user enters a character instead. I have been > trying to use the Type() functio

Re: [Tutor] validation

2007-08-27 Thread Shantanoo Mahajan
On 27-Aug-07, at 2:20 PM, Michael wrote: > Hi > > I am fairly new to Python and I wish to validate input. Such as > wanting > to check and make sure that an integer is entered and the program not > crashing when a naughty user enters a character instead. I have been > trying to use the Type() f

[Tutor] validation

2007-08-27 Thread Michael
Hi I am fairly new to Python and I wish to validate input. Such as wanting to check and make sure that an integer is entered and the program not crashing when a naughty user enters a character instead. I have been trying to use the Type() function but I cannot work out how to check the return