On Saturday, September 26, 2015 at 10:55:57 AM UTC-7, Jori Mäntysalo wrote:
>
> On Sat, 26 Sep 2015, Travis Scrimshaw wrote: 
>
> > I would use: 
> > 
> > if n not in ZZ: 
> >    raise ValueError(...) 
>
> Seems easy. But to make sure: does this work in all cases? I.e. raw Python 
> ints, Sage Integers, maybe something else too? At least QQ(3) in NN seems 
> to work. 
>
> How about positive integers? "n-1 in NN" gives bad error message if n is 
> for example string. "n in NN and n>0"? 
>

try:
    NN(n)
except ValueError:
    handle the error....

or since you want to rule out n=0:

try:
    NN(n-1)
except (ValueError, TypeError):
    handle the error...


-- 
John

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to