1

File Structure:

device
   device.py
   __init__.py

__init__.py contains just one line:

from device import *

device.py just has a bunch of functions, and I want to include all of them with from device import *, except I have to use from device.device import * after pip installing.

How can I get rid of the extra scope so it's just from device import *?

karamazovbros
  • 950
  • 1
  • 11
  • 40

2 Answers2

0

You can add a __all__ = ['one_function_name', 'another_one'] with one_function_name and another_one imported previously in your __init__.py.

The from <package> import * is not a good idea because you will import package that you import in file (the __all__ variable protect against this, see this answer) but it is not a good practice.

edit: sashaaero comment does want you want.

ndclt
  • 2,590
  • 2
  • 12
  • 26
0

Either:

  • move the functions from device.py to __init__.py, or
  • use from .device import * in __init__.py.
Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
  • Hmm, can I get your input on something then. Basically, I'm just making a wrapper so the API functions are handled in one file right now. Does that make device.py sorta extraneous then. I tried the 2nd option and that didn't work. – karamazovbros Jul 24 '19 at 22:59