编程语言
首页 > 编程语言> > Python_包

Python_包

作者:互联网

Python_包

  包是一个分层次的文件目录结构,由模块、子包等组成。包就是文件夹,但该文件夹下必须存在 __init__.py 文件, 该文件的内容可以为空。__init__.py 用于标识当前文件夹是一个包。

  目录结构如下图所示:

# test.py
from source import daily, weekly

print("Daily forecast: ", daily.forecast())
print("Weekly forecast: ")
for number, outlook in enumerate(weekly.forecast(), 1):
    print(number, outlook)
# daily.py
def forecast():
    mystring = "like yesterday"
    return mystring
# weekly.py
def forecast():
    return ['snow', 'more snow', 'sleet', 'freezing rain', 'rain', 'fog', 'hail']

 

标签:Python,py,daily,forecast,文件夹,print,weekly
来源: https://www.cnblogs.com/xieyi-1994/p/13975224.html