[Python] from module import *

Raffaele Salmaso raffaele a salmaso.org
Mar 10 Dic 2019 10:46:47 CET


On Tue, Dec 10, 2019 at 10:35 AM Piergiorgio Pancino <
piergiorgio.pancino at gmail.com> wrote:

> Una alternativa sarebbe impedire l'import star, la domanda infatti verte
> su questo: e' possobile sollevare un'eccezione su questo tipo di import?
>
Definisci __all__

raf at howl € cat lib1.py
__all__ = []

def func():
    print('lib1')
Premi un tasto per continuare...

raf at howl € cat lib2.py
__all__ = []

def func():
    print('lib2')
Premi un tasto per continuare...

raf at howl € cat main.py
from lib1 import *
from lib2 import *

func()
raf at howl € python3 main.py
Traceback (most recent call last):
  File "main.py", line 4, in <module>
    func()
NameError: name 'func' is not defined

-- 
| Raffaele Salmaso
| https://salmaso.org
| https://bitbucket.org/rsalmaso
| https://github.com/rsalmaso
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.python.it/pipermail/python/attachments/20191210/05b9b5d8/attachment.html>


Maggiori informazioni sulla lista Python