I would highly recommend changing this. Use of such hacks are, as I
said fragile, and un-Pythonic. var() is only intended for interactive
use. It's fine to have a similar function for interactive use, but
the main API should use regular name assignment.
Note that even var() doesn't always "work" as regular name assignment.
For example, suppose I have the following:
from sympy import var
def test():
var('x')
print x
def test2():
var('y')
print y
z = 1
test2()
print y
print z
test()
Now, if this worked like it should, the "print y" in test() but not in
test2() should raise a NameError, because it was only defined in the
scope of test2(). But if you run this, you get
x
y
y
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 10, in test
NameError: global name 'z' is not defined
The two "y"s in the output show that the name is defined in both
places. The final NameError shows that this doesn't happen for
normally defined variables.
That's just one thing that can happen with this sort of thing. There
are other things too. Depending on what you do with the frame, it may
not be supported in alternate Python implementations like Jython,
PyPy, or IronPython. And see
http://code.google.com/p/sympy/issues/detail?id=1198 for an example of
where this sort of things would actually be useful, but it doesn't
work in all cases, so isn't.
Aaron Meurer
On Sat, Feb 25, 2012 at 5:16 PM, Alan Bromborsky <[email protected]> wrote:
> On 02/25/2012 05:58 PM, Aaron Meurer wrote:
>>
>> Can someone explain why it's trying to mess with the frame? This is
>> very fragile, and very rarely needs to be done.
>>
>> Aaron Meurer
>>
>> On Sat, Feb 25, 2012 at 5:23 AM, Bharath M R<[email protected]>
>> wrote:
>>>
>>> I have created an issue on the error that I am getting . Please refer
>>> Issue
>>> 3103.
>>> Thanks,
>>> Bharath M R
>>>
>>>
>>> On Friday, February 24, 2012 4:40:29 PM UTC+5:30, Bharath M R wrote:
>>>>
>>>> I created a branch on my desktop and tried to run the tests. All the
>>>> tests
>>>> in test_GA.py are not working. Should I report it as an issue?
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "sympy" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/sympy/-/-6EhDxmVB3sJ.
>>>
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/sympy?hl=en.
>
> I wanted to inject some objects from the function setup() in the class MV in
> the module GA into the name space of the main program. Christian Buhler
> tried to fix some of the problems with my method by using the technique in
> the sympy var() function. I now think it would be better to forget about
> this altogether and remove the code from the program so that the
> only way to get access to the variables is to pass them from the program -
>
> (e1,e2,e3)=MV.setup('e_1 e_2 e_3')
>
> This has the advantage in that the name of the variable does not have to be
> the variable symbol so that one can use a
> short name in the program and a long desrciptive name in the output. In my
> rewrite I print basis bases and blades in boldface. The only objects that
> were injected into the global name space were the basis vectors and there
> are only usually 3 to 6 of them max so that it is not worth the effort to
> inject them!
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.