-1

I understood that there is a way(mentioned here) to import all objects from module using

from testmodule import *

As using '*' causes some confusions while accessing definitions, How can I import only variables from the module?

Community
  • 1
  • 1
srand9
  • 337
  • 1
  • 6
  • 20
  • 1
    `from testmodule import variable` – Rahul K P Mar 22 '17 at 10:00
  • Please read properly the link which you given. The answer in the link itself. – Rahul K P Mar 22 '17 at 10:02
  • As written, your question isn't clear whether you want to import a known limited set of items (which is answered in comments and below and as Rahul points out, is explained in the documentation) OR whether you want to import all of the non-function objects (in which case, clarify the question, although I'm not sure that's easily doable except in the special case where the library was set up for it, e.g. I think pygame had a special literals submodule specifically to pull in stuff to the global scope without completely polluting the namespace, but in general this is still not a good idea) – Foon Mar 22 '17 at 11:00

2 Answers2

1

You will have to specify each variable.

from testmodule import (
    DEF1, DEF2, DEF3, ...
)
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
0

you can import specific variable :

from testmodule import variable_name
Harsha Biyani
  • 7,049
  • 9
  • 37
  • 61