Ask Your Question
0

from __future__ import unicode_literals and variable names

asked 13 years ago

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

Preview: (hide)

Comments

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

Laurent Claessens gravatar imageLaurent Claessens ( 13 years ago )

1 Answer

Sort by » oldest newest most voted
0

answered 13 years ago

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" ...

Preview: (hide)
link

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: 13 years ago

Seen: 710 times

Last updated: Oct 24 '11