man...@gmx.net wrote:
Hi, I suspected it would have something to do with the interpreter.
Thanks for the explanation!
FWIW, if you want it the other way around, i.e., literals as Python ints
or floats in .sage files or at the sage: prompt, you can use the 'r'
suffix ("raw"), which is another feature of the Sage preparser.
I.e., 1r is of type int, 2.5r is of type float.
Type help(preparser) and help(preparse) for a few more examples on the
behaviour of the Sage preparser.
-leif
On Mon, May 20, 2013 at 12:02:43PM +0000, Simon King wrote:
Hi!
On 2013-05-20, man...@gmx.net <man...@gmx.net> wrote:
import bar
type( bar.foo( ) )
returns
<type 'int'>
Needless to say, this causes a bunch of new errors if my code assumes
that I get a sage type (I came across this because I did something like
real( ) on the result).
Is this expected behaviour?
Yes. If you import a Python module, then it is the expected behaviour
that you get a Python <int> and not a Sage Integer.
In interactive sessions (command line or notebook) and when you attach a
.sage-file, then a preparser comes into play. For example:
sage: preparse('1')
'Integer(1)'
sage: preparse('f(x) = x^2')
'__tmp__=var("x"); f = symbolic_expression(x**Integer(2)).function(x)'
sage: preparse('R.<x,y> = QQ[]')
"R = QQ['x, y']; (x, y,) = R._first_ngens(2)"
So, typing "1" in an interactive session results in a Sage Integer
*only* because the preparser makes it so. Similarly, the preparser makes
it possible to define a symbolic function or a polynomial ring in a nice
syntax.
But when you write a Python module then there is no preparser. Hence,
you need to adhere to Python syntax.
Best regards,
Simon
--
() The ASCII Ribbon Campaign
/\ Help Cure HTML E-Mail
--
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.