git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Renaming an import


On 05Sep2019 20:31, Michael Speer <knomenet at gmail.com> wrote:
>pkg/graph.py:
>     from graphing_module_b import plot, axis
>
>pkg/foobar.py:
>     from .graph import plot, axis
>
>Would it be sufficient to use a file for indirection?

Or without a stub file and only slightly less conveniently:

  pkg/__init__.py
    import graphing_module_b as graph

  pkg/foobar.py
    from . import graph
    plot = graph.plot
    axis = graph.axis

Alternatively:

  pkg/__init__.py
    import graphing_module_b as graph
    plot = graph.plot
    axis = graph.axis

  pkg/foobar.py
    from . import graph, plot, axis

Cheers,
Cameron Simpson <cs at cskk.id.au>