On Mon, Mar 30, 2015 at 4:26 AM, Joachim Durchholz <j...@durchholz.org> wrote:
> Hi all,
>
> I'm wondering about the section on creating symbols in
> https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns#strings-as-input
> .
>
> It is mildly discouraging importing from sympy.abc because an accidental
> "from sympy.abc import *" would clobber I and Q (and possibly others), and
> recommends
>>>> import symbols
>>>> x, y, z = symbols('x y z')
> instead.
>
> Now in https://github.com/sympy/sympy/pull/9219 , I applied this advice to
>>>> from sympy.abc import t, w, x, y, z, n, k, m, p, i
> and got
>>>> t, w, x, y, z, n, k, m, p, i = symbols('t w x y z n k m p i')
> I think that's actually really dangerous, because it's easy to swap two
> letters without noticing so you essentially get the equivalent of
>>>> p = Symbol('i')
>>>> i = Symbol('p')
> with the devious consequence that everything would still work but any
> outputs would be utterly confusing because it would print 'p' wherever the
> user expects 'i' and vice versa.

If it's part of a doctest you will catch it immediately. If it's part
of a regular test and never actually uses the name of the symbol, then
I suppose it won't matter, although it will be confusing if someone is
investigating a failing test.

symbols() supports commas, so an easy thing to do here is to use the
form symbols(' t, w, x, y, z, n, k, m, p, i'), so that the left-hand
side of the assignment exactly matches the right-hand side.

Aaron Meurer

>
> So... should I change the wiki to recommend sympy.abc over symbols()?
>
> Regards,
> Jo
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/551916B5.8090808%40durchholz.org.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2B%3DeMV42SwWABMY6S%2BTVbG-Lk-3sFNavPbMdaGtnJ6HaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to