if not import * then what?

2 views
Skip to first unread message

smichr

unread,
Nov 12, 2009, 9:24:28 AM11/12/09
to sympy
I'm just looking for some feedback about what is useful to see in the
documentation. I've finished making all imports explicit in the *py
files and am wondering what is most useful to see in the
documentation.

What should the following be replaced with:

>>> from sympy import *
>>> var('x')
>>> print sqrt(x)

A
>>> from sympy.abc import x
>>> from sympy import sqrt
>>> print sqrt(x)
x**(1/2)

B
>>> import sympy
>>> print sympy.sqrt(x)
x**(1/2)

C
>>> import sympy as s
>>> s.var('x')
x
>>> print s.sqrt(x)
x**(1/2)

If we are trying to get people to learn what's in sympy, the s.foo
format is the most direct instructional format, I think. Are there
other ideas? What do you think?

/c

Sebastian Haase

unread,
Nov 12, 2009, 10:31:12 AM11/12/09
to sy...@googlegroups.com
numpy people use
import numpy as np
and often
import scipy as sp
and
from matplotlib import pyplot as plt

How about
import sympy as S

(for my part I still use import numpy as N -- historical relict from
Numeric and numarray)

Both lower case "s" and unabbreviated "sympy" seem bad choices for me ...


My two cents,

Sebastian Haase

Gael Varoquaux

unread,
Nov 12, 2009, 12:04:59 PM11/12/09
to sy...@googlegroups.com
On Thu, Nov 12, 2009 at 04:31:12PM +0100, Sebastian Haase wrote:

> numpy people use
> import numpy as np
> and often
> import scipy as sp
> and
> from matplotlib import pyplot as plt

> How about
> import sympy as S

> (for my part I still use import numpy as N -- historical relict from
> Numeric and numarray)

> Both lower case "s" and unabbreviated "sympy" seem bad choices for me ...

How about: 'smp'? 'S' is capital, and I like to keep that for classes. In
addition, it is very short, and thus it seems easy to overright it.

Gaël

PS: I am aware the SMP means 'symetric multiprocessor'.

Ondrej Certik

unread,
Nov 12, 2009, 1:08:57 PM11/12/09
to sy...@googlegroups.com

I don't have any strong feelings on this, as long as it is explicit,
e.g. all A, B, C is fine.

I myself just use a combination of A/B. I don't like C much. Saving 3
characters, e..g "np" instead of "numpy" --- well, I don't find it
worthy. Saving 2 characters in "smp" instead of "sympy", well, that
sounds even less worthy to me. But as I said, I think it's up to you.
I think we can even combine all A/B/C in the docs.

Ondrej

andy2O

unread,
Nov 12, 2009, 2:33:16 PM11/12/09
to sympy


On Nov 12, 2:24 pm, smichr <smi...@gmail.com> wrote:
> I'm just looking for some feedback about what is useful to see in the
> documentation. I've finished making all imports explicit in the *py
> files and am wondering what is most useful to see in the
> documentation.
>
> What should the following be replaced with:
>
> >>> from sympy import *
> >>> var('x')
> >>> print sqrt(x)

*Personally*, I'd suggest staying with 'from sympy import *' because
the context is sympy as an interactive maths environment and keeping
the code simple and compact is best to introduce sympy. It makes sympy
work more like Mathematica and Maple which users may be used to.

I would leave instruction on best practice in Python scripting to
comments in the documentation web pages and other Python tutorials.
People will look at the sympy help text to learn how to use sympy's
functions, not as a general introduction to best practice in full
Python scripting.

(This is just a personal opinion, so please take or leave this as you
like)

best regards,
andy

Ondrej Certik

unread,
Nov 12, 2009, 2:42:06 PM11/12/09
to sy...@googlegroups.com

There is a problem with mixing sympy and numpy together. E.g. for
example we use it in femhub (femhub.org) and it is a source of common
confusion, if sin(x) is a symbolic sin(x), or if it is numeric (numpy)
sin(x). E.g.

from sympy import *
from numpy import *

is simply confusing. So, I would do it the other way round --- I would
put there a note that you can use isympy, where things are imported
for you automatically, but in documentation I would use explicit
imports, so that users can just copy & paste it in their scripts and
it would work.

Ondrej

Reply all
Reply to author
Forward
0 new messages