ABC公司#
本模块将所有拉丁语和希腊语字母导出为符号,因此您可以方便地执行以下操作
>>> from sympy.abc import x, y
而不是看起来有点笨重
>>> from sympy import symbols
>>> x, y = symbols('x y')
告诫#
1. As of the time of writing this, the names O
, S
, I
, N
,
E
, and Q
are colliding with names defined in SymPy. If you import them
from both sympy.abc
and sympy
, the second import will "win".
This is an issue only for * imports, which should only be used for short-lived
code such as interactive sessions and throwaway scripts that do not survive
until the next SymPy upgrade, where sympy
may contain a different set of
names.
2此模块不根据需要定义符号名称,即。 from sympy.abc import foo
will be reported as an error because sympy.abc
does not contain the name foo
. To get a symbol named foo
, you still need to use Symbol('foo')
or symbols('foo')
. You can freely mix usage of sympy.abc
and Symbol
/symbols
,尽管坚持使用一种且只有一种方法来获取符号确实会使代码更具可读性。
该模块还定义了一些特殊名称,以帮助检测哪些名称与默认的SymPy名称空间冲突。
_clash1
定义所有与SymPy对象冲突的单字母变量; _clash2
定义多字母冲突符号;以及 _clash
是两者的结合。这些都可以 locals
在辛化过程中,如果一个人想要符号而不是非符号对象。
实例#
>>> from sympy import S
>>> from sympy.abc import _clash1, _clash2, _clash
>>> S("Q & C", locals=_clash1)
C & Q
>>> S('pi(x)', locals=_clash2)
pi(x)
>>> S('pi(C, Q)', locals=_clash)
pi(C, Q)