[Tutor] accessing modules found throughout a package?

Alex Kleider akleider at sonic.net
Sun Oct 18 11:33:50 EDT 2015


On 2015-10-18 08:07, Alex Kleider wrote:
> On 2015-10-17 19:49, Steven D'Aprano wrote:
> 
>> which will work from your package's callers, and from within the 
>> package
>> itself provided the top level directory can be found within Python's
>> path. Within the package you can also use relative imports, see the
>> docs for more detail.
> 
> How does one arrange so "the top level directory _can_ be found within
> Python's path."?
> 

Is the answer to include the following at the beginning of each file?

if not 'path/to/top/level/package/directory' in sys.path:
     sys.path.append('path/to/top/level/package/directory')




More information about the Tutor mailing list