0

I'm new to python development and the mindset for Python in general, so I'm still learning the generally accepted practices of the language and infrastructure. Background on the problem:

I have installed into Windows Python, pip, etc. as well as the module pymeasure, which provides a good start for controlling bench equipment through python. This module is not equipment comprehensive, however, and I need to develop my own additional scripts within the pymeasure framework to specifically control the equipment I use. I have created a (very rough) sketch of control code for an Agilent E3647A power supply. When I located the python script in the module directory (buried far into my userspace folder structure) everything was fine.

I will be developing software as part of a larger group of developers, all of whom will be sharing code through an internal git repository. Any code we create (not downloaded from git) should be located in the git repository. Ergo, my E3647A script should be in the repo folder (somewhere).

Failed __init__ implementation

In copy/paste form:

from .agilent8257D import Agilent8257D

from .agilent8722ES import Agilent8722ES

from .agilentE4408B import AgilentE4408B

from .agilentE4980 import AgilentE4980

from .agilent34410A import Agilent34410A

from .agilent34450A import Agilent34450A

from .agilent4156 import Agilent4156

from .agilent33220A import Agilent33220A

from .agilent33500 import Agilent33500

from .agilent33521A import Agilent33521A

from .agilentB1500 import AgilentB1500

from 'C:\Bench_Software\Equipment\Equipment Single Commands\agilentE3647A' import AgilentE3647A

The above attempt to add a non-local script into __init__ fails miserably.

How (if possible) can I specify absolute paths to module scripts, or change my entire Python target for modules to look for multiple directories, split existing modules along pip-downloaded vs. locally-developed code? Are there any standard code practices to achieve such a thing?

torek
  • 448,244
  • 59
  • 642
  • 775
  • Remember to wrap copy-pasted code in triple backticks (\`\`\`) in order to create a code block. Helps with readability. – crock Jun 15 '22 at 23:25
  • Python imports use module names, not strings; the module name will just be `agilentE3647A`, or perhaps something more qualified like `mod.ule.agilentE3647A`. The mapping from *search path* to *module* is where the magic happens. See, e.g., [adding directory to sys.path /PYTHONPATH](https://stackoverflow.com/q/16114391/1256452). I don't keep up with [tag:python] very well (it's far too active on StackOverflow) so there may be better Q&As, this is just the first one I found. (Generally you want a virualenv and/or pip setup file.) – torek Jun 16 '22 at 10:01
  • Thanks Torek, venv was the solution I finally went with. I'm not thrilled needing to create a venv just to work within a git repository, but since I don't know python enough to understand a different "correct" way, this seems to be the best solution. – Hugh Eisenman Jun 17 '22 at 00:46

0 Answers0