sympify() works independently of what you already have defined. So for
instance,
x = 1
print(sympify('x')) # prints x
This produce Symbol('x'), not 1. If you want it to use what you
already have defined, you can pass locals() as the second argument to
sympify()
x = 1
print(sympify('x', locals()) # prints 1
The best recommendation is in general to avoid sympify, unless you are
processing arbitrary strings. Instead, build your expression up
directly using Python operations, like in your first examples.
Aaron Meurer
On Fri, Feb 14, 2020 at 4:26 PM ludi <[email protected]> wrote:
>
> Thanks a lot
>
> I read about locals and individual dictionaries, but I didn't realize that it
> would affect "already defined" Symbols.
> It is a little bit confusing that 'a' and 'a' can be not the same thing.
>
> But now everything works as expected, thanks again.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/5d9325aa-6eb4-4340-af0d-5e0f3a93c419%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BG6ZVLa4BuJgUAQ3dBi3ZXeLQTBOB3E3405mtje1baag%40mail.gmail.com.