【发布时间】:2020-04-13 05:35:51
【问题描述】:
我制作了包含以下代码的文件'DWDfunctional.py':
def ForecastDownloader(system,ModelName,year,Month):
import cdsapi
c = cdsapi.Client()
c.retrieve(
'seasonal-monthly-single-levels',
{
'originating_centre': ModelName,
'system': system,
'variable': 'total_precipitation',
'product_type': 'monthly_mean',
'year': year,
'month': Month,
'area' : [40, 44, 24, 64],
'leadtime_month': [
'1', '2', '3',
'4', '5', '6',
],
'format': 'netcdf',
},
'dwd.nc')
然后我在另一个文件中调用了该函数:
from DWDfunctional.py import ForecastDownloader
ForecastDownloader('2','dwd',2020,2)
我在想,当我运行上面两行代码时,python 执行另一个文件夹中的另一个旧代码!!!并以错误的文件名下载错误的文件而没有错误!
【问题讨论】:
-
我又想知道,当我调用“DWDfunctional.py”中的函数时,它会正确执行!它运行正确。但我需要在该文件之外调用函数。
-
导入后,您可以检查
module.__file__以查看您的模块来自何处。并从导入中删除.py,只需名称就足够了。 -
如何检查 module.__file__
-
ForecastDownloader.__file__ -
请将此帮助添加为该问题的答案,以便我接受