[Python] How do I export custom modules in python through __init__.py [duplicate]

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to export a Python function from server -> utils -> math math.py old_div

    import numbers


    def old_div(a, b):
    """
    Equivalent to ``a / b`` on Python 2 without ``from __future__ import
    division``.
    """
    instancetance(a, numbers.Integral) and isinstance(b, numbers.Integral):
    return a // b
    return a / b


    I have created in utils __init__.py and put export from ..utils.math import old_div there so that I can export it to another directory. But I get an error:

    File "f:\Balckhole\server\utils\__init__.py", line 1, in <module>
    from ..utils.math import old_div
    ImportError: attempted relative import with no known parent package


    How could I resolve the error and export it -- I have the virtual environment set up. How could I solve this error?

    Continue reading...

Compartilhe esta Página