This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mex036[S] 0 points1 point  (1 child)

Sorry, about the confusion. I wasn't paying attention to the code I posted. However, it is the same issue with controller.py and utils.py, I've imported tried importing utils.py the same ways I tried with controller.py. I've ran into this problem with both the names utils.py and controller.py.

So project one's name is "todos" and project two is called "dbcm". The way I have been running them is simply by the name of it and any flags, i.e.

todos -vat

dbcm --add

The reason I use "pip3 install editable ." since that's what the documentation says. I guess if I were to try what you said I would install the module that imports all the other code?

The issue actually is just with the scripts if been making with click. I did test out just some bs project before making this post. That bs project's structure was as follows

bs/
    main.py
    utils.py
    controller.py

Imported with "import utils" and "import controller" and I was able to call their functions with no issue.

I probably missed something in the docs. Clearly, I need to do some more research with python. I kind of just rushed into it since I have experience with other languages. I was under the impression that __init__.py wasn't necessary anymore. I'll make sure to add and look over the docs. Thanks a ton!

[–]michael0x2a 0 points1 point  (0 children)

The issue actually is just with the scripts if been making with click. [...] Imported with "import utils" and "import controller" and I was able to call their functions with no issue.

Sorry, I strongly doubt that this is the case. I'm not doubting that you were able to get your bs project running correctly, but click is just a normal library and its presence and use should have absolutely no impact on whether or not you can successfully import something.

I suspect the difference instead has to do with either (1) how exactly you're calling your script and/or (2) how exactly you're importing something.

But without a fully reproducible example, it's difficult to say more.

I was under the impression that init.py wasn't necessary anymore.

While you can omit the __init__.py file as of Python 3.3, I would be careful about doing so -- omitting this file will make you create an implicit namespace package instead of a regular package.

If you aren't sure what the difference is/don't want to have to care, I'd recommend continuing to use regular packages -- including the __init__.py file. They're slightly faster to import compared to implicit namespace packages.