ShannonChenCHN / APythonTour

Yes, beautiful is better than ugly.
MIT License
0 stars 2 forks source link

[问题] 如何理解 if __name__ == '__main__'? #20

Open ShannonChenCHN opened 6 years ago

ShannonChenCHN commented 6 years ago

示例

文件 download.py 中的代码如下:


def get_images():
    return ['logo', 'tree', 'mountain']

def download_images():
    pass

if __name__ == '__main__':
    download_images()

文件 print.py 中的代码如下:

import download  # 引入 download 模块

def print_images():
     images = download.get_images()
     for image_name in images:
         print(image_name)

参考