When you index an iterable the __index__ method is used, so Sage integers 
will work in many contexts.

On Tuesday, 14 May 2013 12:06:35 UTC-7, John H Palmieri wrote:
>
> Why does Python handle Sage Integers well in some cases but not in others? 
> For example:
>
>     $ sage --python
>     Python 2.7.4 (default, May  8 2013, 16:25:06) 
>     [GCC 4.7.3] on darwin
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> from sage.all import Integer
>     >>> L = range(5)
>     >>> L[Integer(2)]  # works!
>     2
>
>     >>> import re
>     >>> matches = re.match("(?:foo)?(bar)?(sws)?", "foobarsws")
>     >>> matches.group(0)
>     'foobarsws'
>     >>> matches.group(Integer(0))   # doesn't work!
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     IndexError: no such group
>
> What would we need to do to make matches.group(Integer(0)) work? Note that 
> when using Sage, rather than Python, if you evaluate "matches.group(0)", it 
> gets preparsed to "matches.group(Integer(0))". I forget to use "int(0)" as 
> the argument, and then I get annoyed by the "no such group" error. (See 
> http://ask.sagemath.org/question/1520/python-thing-that-doesnt-work-in-sage-works-infor
>  a similar question.)
>
> -- 
> 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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to