Ask Your Question
0

from __future__ import unicode_literals and variable names

asked 2011-10-24 06:50:00 +0100

Hello

It seems that making

from __future__ import unicode_literals

create some strange behaviour in Sage :

sage: from __future__ import unicode_literals
sage: x=var('x')
sage: f(x)=x**2   #ok
sage: f(3)
9
sage: f(x=3)    # Not ok at all
u'x'^2

While it works when I force the argument of var to be str:

sage: y=var(str('y'))
sage: f(y)=y**2
sage: f(3)       #ok
9
sage: f(y=3)     #ok again
9

Should I forget about unicode_literals or open a ticket agains the var function which should convert its argument into a str ?

Thanks for advises

Laurent

edit retag flag offensive close merge delete

Comments

The same in a docstring works when tested by sage -t : f(x=3) returns 9.

Laurent Claessens gravatar imageLaurent Claessens ( 2011-10-24 07:54:27 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-10-24 08:25:20 +0100

This is not really an answer, but adding that on the top of my module helps :

class WrapperStr(object):
    def __init__(self,fun):
        self.fun=fun
    def __call__(self,arg):
        return self.fun(str(arg))

var=WrapperStr(var)

I just have to replace var('x') by x=var('x') and it works at least better than before.

However, this seems not satisfactory and I'm expecting many "border effects" ...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-10-24 06:50:00 +0100

Seen: 694 times

Last updated: Oct 24 '11