Re: python3 package import difference?

Liste des GroupesRevenir à cl python 
Sujet : Re: python3 package import difference?
De : rs.quim (at) *nospam* gmail.com (Ronaldo Sc)
Groupes : comp.lang.python
Date : 08. Aug 2024, 00:22:33
Autres entêtes
Message-ID : <mailman.31.1723070433.2890.python-list@python.org>
References : 1 2
I believe you will need to track the modules in the folder  *dbi  *in the
root file '__init__.py'.

So there's an alternative to use the statement __all__ in the root filet
__init__.py, check the link where I find a use case:

*https://sentry.io/answers/what-is-init-py-for-in-python/#using-__init__py-to-run-code-and-control--imports
<https://sentry.io/answers/what-is-init-py-for-in-python/#using-__init__py-to-run-code-and-control--imports>*


References to take more deep in those issues:
PEP-3147 <https://peps.python.org/pep-3147/>
https://docs.python.org/3/tutorial/modules.html
<https://docs.python.org/3/tutorial/modules.html#intra-package-references>
     in this link above we have some examples of relative imports:
    from . import echo
    from .. import formats
    from ..filters import equalizer


In your code you're using "import *" , this is not a good practice when
using only some features in your module(s) because you'll inject more
garbage into memory if there are features you're not using.

Share with us the updates on your code.

Ronaldo

Em qua., 7 de ago. de 2024 às 14:40, Tobiah via Python-list <
python-list@python.org> escreveu:

I have an old library from 20 some years ago
for use with python2, that is structured like this:
>
     rcs
     ├── dbi
     │   ├── __init__.py
     │   ├── dbi.py
     │   └── regos.py
     └── __init__.py  --   *empty*
>
>
the __init__.py file under 'rcs' is empty.
The one under rcs.dbi contains:
>
     from dbi import *
     from regos import *
>
>
With python2, I'd go:
>
         import rcs.dbi
>
then I'd have access to stuff in regos.py
as:
>
         rcs.dbi.feature()  (Where 'feature' is defined in regos.py)
>
>
When I do the same import with python3, I get:
>
     Traceback (most recent call last):
       File "/home/toby/me", line 1, in <module>
         import rcs.dbi
       File "/usr/regos-1.0/lib/python/rcs/dbi/__init__.py", line 1, in
<module>
         from dbi import *
     ModuleNotFoundError: No module named 'dbi'
>
>
What's changed, and how do I fix it?
>
>
Thanks!
--
https://mail.python.org/mailman/listinfo/python-list
>

Date Sujet#  Auteur
7 Aug 24 * python3 package import difference?5Tobiah
7 Aug 24 +- Re: python3 package import difference?1Stefan Ram
8 Aug 24 +- Re: python3 package import difference?1Ronaldo Sc
8 Aug 24 +- Re: python3 package import difference?1Chris Angelico
8 Aug 24 `- Re: python3 package import difference?1Cameron Simpson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal