国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Why can't Python's __all__ prevent "content that is not exported cannot be accessed"?
大家講道理
大家講道理 2017-05-18 10:50:54
0
2
877

Actual Phenomenon

  1. Expect __all__ Be able to control module access

  2. According to the community contract, private things start with _, but recently I found that a colleague adjusted the private interface (a module I wrote)

  3. Python is a flexible language, and the unwritten rule is "convention over configuration"

Expected Phenomenon

  1. I searched for information on __all__, and thought it could meet my requirements, but it didn’t (see below)

question

So, __all__ seems to be of no use at all?

Related codes

  • base.py

__all__ = ('a', 'b', )

a = 1 
b = 2 
c = 3    # 不希望別人訪(fǎng)問(wèn) 
  • test.py

import base
                                                                                                            
print(base.c)
  • Output

3

environment

  • Python 2.7

大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

reply all(2)
過(guò)去多啦不再A夢(mèng)

test.py file changed to

from base import *

print a
print b
print c

The results are as follows:

? python test.py                                                                                                                                                                                                                            ?
1
2
Traceback (most recent call last):
  File "test.py", line 8, in <module>
    print c
NameError: name 'c' is not defined
曾經(jīng)蠟筆沒(méi)有小新

Nothing is truly private in Python

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template