Kent Johnson wrote:
Is this the way to define my own error and to use it:
class MyValueError(Exception):
define initialization and printing
You usually don't need to define anything extra, the Exception methods are fine.
I think there could be confusion over what you meant w
On Fri, Oct 16, 2009 at 9:44 AM, Robert Johansson
wrote:
> If I wanted prompt to be an integer, is my check with range still bad?
If the prompt is coming from raw_input() then you have already
guaranteed it is an integer when you convert it in a try/except block.
> Is this the way to define my o
> What if a valid user input has to be an integer between 10 and 20? I mean,
> it could be that you are doing something that only makes sense for that
> input. Would it be pythonic to add a test like:
>
> If prompt in range(10,21):
Better to write
if 10 <= prompt <= 20:
> ...
> else:
> ... ra
"Robert Johansson" wrote
What if a valid user input has to be an integer between 10 and 20?
Would it be pythonic to add a test like:
If prompt in range(10,21):
...
else:
... raise an error
Yes and it could be a ValueError in this case.
You could also test using conditions which, for a w
Robert Johansson wrote:
Hi,
I'm writing a text based menu and want to validate the user input. I'm
giving the options as integers, and I want to make sure the user enters a
proper value.
Here's what I've got so far: http://pastebin.com/m1fdd5863
I'm most interested in this segment:
while True
On Fri, Oct 16, 2009 at 7:25 AM, Robert Johansson
wrote:
> What if a valid user input has to be an integer between 10 and 20? I mean,
> it could be that you are doing something that only makes sense for that
> input. Would it be pythonic to add a test like:
>
> If prompt in range(10,21):
Better
> Hi,
> I'm writing a text based menu and want to validate the user input. I'm
> giving the options as integers, and I want to make sure the user enters a
> proper value.
> Here's what I've got so far: http://pastebin.com/m1fdd5863
> I'm most interested in this segment:
> while True:
>
Katt wrote:
Message: 3
Date: Thu, 15 Oct 2009 16:50:57 +0100
From: Rich Lovely
To: Wayne Werner
Cc: "tutor@python.org"
Subject: Re: [Tutor] Most pythonic input validation
Message-ID:
Content-Type: text/plain; charset=windows-1252
2009/10/15 Wayne Werner :
Hi,
I'm writi
Message: 3
Date: Thu, 15 Oct 2009 16:50:57 +0100
From: Rich Lovely
To: Wayne Werner
Cc: "tutor@python.org"
Subject: Re: [Tutor] Most pythonic input validation
Message-ID:
Content-Type: text/plain; charset=windows-1252
2009/10/15 Wayne Werner :
Hi,
I'm writing a text based m
On 10/15/2009 7:36 AM Wayne Werner said...
Is that the most pythonic way of validating? Is there a better way?
Pythonic in part having been addressed, I've some further comments to
your valid_choice code... -- Emile
def valid_choice(choice, min, max):
# don't use min and max -- they shadow
2009/10/15 Wayne Werner :
>
>
> On Thu, Oct 15, 2009 at 10:50 AM, Rich Lovely
> wrote:
>>
>> 2009/10/15 Wayne Werner :
>> > Hi,
>> > I'm writing a text based menu and want to validate the user input. I'm
>> > giving the options as integers, and I want to make sure the user enters
>> > a
>> > prope
On Thu, Oct 15, 2009 at 10:50 AM, Rich Lovely wrote:
> 2009/10/15 Wayne Werner :
> > Hi,
> > I'm writing a text based menu and want to validate the user input. I'm
> > giving the options as integers, and I want to make sure the user enters a
> > proper value.
> > Here's what I've got so far: http:
2009/10/15 Wayne Werner :
> Hi,
> I'm writing a text based menu and want to validate the user input. I'm
> giving the options as integers, and I want to make sure the user enters a
> proper value.
> Here's what I've got so far: http://pastebin.com/m1fdd5863
> I'm most interested in this segment:
>
Hi,
I'm writing a text based menu and want to validate the user input. I'm
giving the options as integers, and I want to make sure the user enters a
proper value.
Here's what I've got so far: http://pastebin.com/m1fdd5863
I'm most interested in this segment:
while True:
choice = raw_
14 matches
Mail list logo