1 | initial version |
Ah! This is because range(1,10)
is a pure Python command and so returns Python ints. Which, as we are using Python 2, return like this.
sage: preparser(False)
sage: 1/2
0
sage: preparser(True)
sage: 1/2
1/2
But once you use p/7
, Sage's preparser says "That's the rational number p/7" and so does this correctly.
sage: preparse('p/7')
'p/Integer(7)'
A better solution is to use srange
, which always uses Sage types if it can.
sage: srange(1,10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
sage: [type(i) for i in srange(1,10)]
[<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>,
<type 'sage.rings.integer.Integer'>]