how to import only the class methods in python

后端 未结 5 1999
梦谈多话
梦谈多话 2020-12-19 04:50

I have a GP.py file that I am then running a MyBot.py file from.

In the MyBot.py file, I have the line

from GP import *

I have a su

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 05:32

    _single_leading_underscore: weak "internal use" indicator. E.g. from M import * does not import objects whose name starts with an underscore.

    Use this instead:

    from GP import SomeClass
    

    Have a look at PEP-8 (Python Guidelines) if you want to use import *

    Modules that are designed for use via from M import * should use the __all__ mechanism to prevent exporting globals

提交回复
热议问题