|
From: Scott C. L. <sli...@ca...> - 2012-10-31 14:22:48
|
Howdy Luke,
On 29 Oct 2012, at 13:53, Dale Lukas Peterson wrote:
> Richard,
> I am running Python 3.2. In order to run python control, I have to
> use the 2to3 tool to convert on each .py file. It fixes things like
> print "x" by changing it to print("x"). For some reason, it is
Is anyone ensuring that running the 2to3 tool is sufficient for use of python-control with Python 3, or otherwise working on a script that makes necessary changes?
>
> I think this may stem from how src/__init__.py and each of the modules
> in src/ are importing each others functionality. The design patterned
> that I have been following and have used with no issues in the sympy
> project can be seen in these two files:
> https://github.com/hazelnusse/sympy/blob/master/sympy/physics/mechanics/__init__.py
> https://github.com/hazelnusse/sympy/blob/master/sympy/physics/mechanics/particle.py
>
> Basically, in each module, we set the __all__ list to include the
> names of the publicly available class and functions. Within each
> module, we never do relative imports, we always use the absolute
> import syntax. The __init__.py file is heavily commented so you
> should be able to see how we make those symbols available when people
> import the module or sub-package.
While that design pattern is nice, it may not yet be warranted for python-control, which is contained entirely in a single directory with no subpackages. The simplest change I see to avoid the import error you found is below (given as diff output).
~Scott
Index: src/statesp.py
===================================================================
--- src/statesp.py (revision 211)
+++ src/statesp.py (working copy)
@@ -82,7 +82,6 @@
from scipy.signal import lti
import warnings
from lti import Lti, timebaseEqual, isdtime
-import xferfcn
class StateSpace(Lti):
@@ -511,7 +510,7 @@
[1., 1., 1.]].
"""
-
+ from xferfcn import TransferFunction
if isinstance(sys, StateSpace):
if len(kw):
raise TypeError("If sys is a StateSpace, _convertToStateSpace \
@@ -519,7 +518,7 @@
# Already a state space system; just return it
return sys
- elif isinstance(sys, xferfcn.TransferFunction):
+ elif isinstance(sys, TransferFunction):
try:
from slycot import td04ad
if len(kw):
Index: src/xferfcn.py
===================================================================
--- src/xferfcn.py (revision 211)
+++ src/xferfcn.py (working copy)
@@ -81,7 +81,7 @@
from copy import deepcopy
from lti import Lti, timebaseEqual, timebase, isdtime
from warnings import warn
-import statesp
+from statesp import StateSpace
class TransferFunction(Lti):
@@ -308,7 +308,7 @@
"""Add two LTI objects (parallel connection)."""
# Convert the second argument to a transfer function.
- if (isinstance(other, statesp.StateSpace)):
+ if (isinstance(other, StateSpace)):
other = _convertToTransferFunction(other)
elif not isinstance(other, TransferFunction):
other = _convertToTransferFunction(other, inputs=self.inputs,
@@ -868,7 +868,7 @@
"_convertToTransferFunction cannot take keywords.")
return sys
- elif isinstance(sys, statesp.StateSpace):
+ elif isinstance(sys, StateSpace):
try:
from slycot import tb04ad
if len(kw):
knoxville:python-control-py3%
|