2to3 change direct import to relative import

Vincent Vande Vyvre vincent.vandevyvre at swing.be
Thu May 10 03:34:11 EDT 2012


Hi,

I use 2to3 into a python script wich convert all .py files of an
application.

2to3 is executed into the same directory as files.

All import are now relative import:

-----------------------------------------
--- main_ui.py (original)
+++ main_ui.py (refactored)
@@ -15,18 +15,18 @@
 
-from ui_toolBar import ToolBar
-from ui_properties import PropertiesPanel
-from ui_menu import MenuBar
-from ui_statusBar import StatusBar
-from trailer import Trailer
...
+from .ui_toolBar import ToolBar
+from .ui_properties import PropertiesPanel
+from .ui_menu import MenuBar
+from .ui_statusBar import StatusBar
+from .trailer import Trailer
...
--------------------------------------------
Of course the application don't run:
    from .ui_toolBar import ToolBar
  ValueError: Attempted relative import in non-package

2to3 help don't help me about that.

Thank's for any advice.
-- 
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte+7
<https://launchpad.net/qarte+7> . PaQager <https://launchpad.net/paqager>




More information about the Python-list mailing list