0

Assume this package:

  mylibrary/
    ...
    setup.py
    service_stubs/
      __init__.py
      service_pb2.py
      service_pb2_grpc.py

I want that when I import the sub package, all the modules will be available on the package. Tried to put in my __init__.py:

from . import *

And then using like so:

import service_stubs
service_stubs.service_pb2.something_inside_the_module

However this does not work, says service_pb2 module not found. I have to import service_stubs.service_pb2 before for that to work.

If I change __init__.py to:

from . import service_pb2

Then it does work fine.

But, I don't want to explicitly import every module inside the package, since many modules will be there.

Why from . import * does not export name on the package, the same way as from . import something?

And what simple way will solve this?

user3599803
  • 6,435
  • 17
  • 69
  • 130

0 Answers0