[Tutor] Concerning relative import paths

David Aldrich David.Aldrich at EMEA.NEC.COM
Mon Mar 14 13:19:05 EDT 2016


Hi



My Python project's directory structure looks like this:



myproj ----- gui

         |

         |-- python



The 'gui' folder contains my main.py. The 'python' folder contains various modules that we have written.



My gui/main.py contains this sort of import code:



import os, sys

sys.path.append('../python')

import MyClass



This works fine at runtime.



The thing is that I am using Microsoft's Visual Studio Code editor with an extension that implements Intellisense for Python.  The Intellisense is working fine for the os and sys modules, but it doesn't respond to MyClass.  This seems reasonable because I guess it ignores the sys.path.append line.



My question is: is there a better way that I can specify the import statements so that a tool such as Intellisense will have an absolute path to find the modules?



I hope this isn't too tool specific, I'm just wondering whether there's a more pythonic way of implementing this import code?



Best regards



David






More information about the Tutor mailing list