0

I am a beginner in Python and I am wondering how to prevent methods starting with an underscore (_) from being imported. I have a class called Scrapper which has four methods: get, save, _is_data_available, and _collecting_data. I only want the get and save methods to be imported by other modules.I tried adding all = ['get', 'save'] outside the class, but this did not work. How can I do this?

2
  • 1
    A method can't be imported, because it belongs to the namespace of a class, not a module. So __all__ doesn't have an effect here. Commented Aug 23, 2023 at 10:23
  • The underscore is sufficient. If a third-party caller chooses to ignore that convention, you should never try to prevent it. (Of course, if your own code ignores it, that's a bug which needs fixing). Commented Aug 23, 2023 at 10:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.