Nice, but still somewhat confusing.
Well, it’s an example. All projects have slightly (or sometimes very)
different layouts and conventions. But loosely speaking: put your new
code in with other code of the same or similar purpose, wherever that
place turns out to be.
I firmly believe that to be a successful coder, and I am deliberately not using “software engineer” , one has to adapt to the language terminology and try to consistently use it.
After coming from C it looks as if python is not a code , but a script… Do not get me wrong - I am not pushing terminology just to be an ass , but without it - starting any language is a mess.
The distinction’s somewhat arbitrary. But Python is a
run-it-when-imported language. C and other static languages have a
distinct “compile and link” step. There are parallels in Python, but in
terms of feel that’s perhaps what you’re seeing. Of coure there are
other differences as well.
So I still have module = package = folder. ( And PyCharm "added .py file " …)
Ok, not quite.
.py file is a module. A file
foo.py can be imported as
foo (maybe with a prefix depending on where in the source
tree it is).
A package is a directory with multiple
.py files inside it. If you’ve
got a directory named
Then you can
import foo, and it imports the
foo/__init__.py file. Or
import foo.bah and it imports the
foo.bah.py file. So
is a kind of “default” module to load if you ask for just
purpose is to initialise that package (if that’s necessary at all; this
can be an empty file and these days is even optional).
So I ended up with this
from src.NanoVNASaver.Windows.AA7EJ_ADDS.Debug_Module import introduction
therefore a question
do I have to copy the “full path”
(src.NanoVNASaver.Windows.AA7EJ_ADDS.Debug_Module) or is there a way I
can "define it " as a constant ?
It looks to me like this Python project keeps all its Python code in a
src/ subdirectory. This is very common.
Normally the environment you’re working in will have that
subdirectory in the
$PYTHONPATH, so that it is one of the normal
places to look in for imports. With that setting your import would be:
Usually you’d have some kind of environment file to source which would
arrange that for you (the
$PYTHONPATH)while you’re working there.
Cameron Simpson email@example.com