directory - Typical Naming Conventions for Python Directories in Packages -
the question
know if there standard convention naming of python directories plan imported module. meaning directory contains blank __init__.py
background
until have given little thought , named solely based on made sense @ file system level. got me in trouble made sense @ file system level made sense other developers' standalone modules. consider following directory:
+ drivers + prologix - __init__.py - driver_a.py - driver_b.py + visa - __init__.py - driver_a.py - driver_b.py __init__.py ringout.py <-- simple file ring-out drivers
while worked fine when ringing out prologix's drivers, ran issue when trying import visa drivers pyvisa's 'visa' module. easy diagnose problem, fix rename visa driver's folder 'visa_dir' makes code more difficult read (imo).
import drivers.visa
vs
import drivers.visa_dir
is there better way handle this?
each module's namespace unique, if have 2 modules named visa
long avoid importing them same namespace same name won't have problems. tend prefer absolute imports:
import drivers.visa import pyvisa.visa
or use as
:
from drivers import visa pyvisa import visa pyvisa
...etc. careful how import things. i'd prefer (as end-user) structure modules logically within package , not worry pre-mangling them me.
Comments
Post a Comment