From: Richard M. <mu...@cd...> - 2012-10-31 17:27:39
|
2to3: does anyone have experience in making packages compatible with both python 2 and python 3? It would be great to have the code do all of the work. import loops: if you have a chance, Luke, can you try out Scott's change and see if it works on python 3. I'll try to install it over the weekend and try it myself, but would be good to get another check. -richard On 31 Oct 2012, at 7:22 , Scott C.Livingston <sli...@ca...> wrote: > 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% > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_sfd2d_oct > _______________________________________________ > python-control-discuss mailing list > pyt...@li... > https://lists.sourceforge.net/lists/listinfo/python-control-discuss |