我尝试将两个字符串Start='2018-07-01'
和End='2019-07-01'
从一个脚本mainfile.py
传递到另一个脚本plot.py
。
在这里,这些日期是用来给地块命名的
mainfile.py:
from choose_weatherstation import Choose_Weatherstation
# from summary import scatter_size
#choose_weatherstation is the function: Input has to be
'Weatherstation',perhour(true/false), weather(false/true)
save(True/false),statistic (true/False)
Start='2018-09-01'
End='2018-12-31'
Choose_Weatherstation('Zeeland',Start,End,True,True,True,True)
plot.py
import matplotlib.pyplot as plt
import seaborn as sns
from mainfile import Start, End
Start=mainfile.Start
End=mainfile.End
def three_plot(condition,plot1,plot2,plot3,filename,Save=False):
...(Not of interest here)
根据我在其他线程中读到的内容,我尝试导入以下两个变量:
from mainfile import Start, End
但是,当我这样做时,会出现以下错误cannot import name 'Choose_Weatherstation' from 'choose_weatherstation' (L:\Improved Code\venv\choose_weatherstation.py)
这是指脚本mainfile.py
的第一行,在这里我导入Choose_Weatherstation from choose_weatherstation.py
当我不尝试导入Start
和End
时,没有发现错误
有人能解释一下我做错了什么吗
正确的语法是:
因此,从字面上看,“from mainfile.py”导入“Start”和“End”对象。
看起来你有正确的导入
您不必拨打:
如果直接从模块导入变量。只需在导入时传递它:
可能出现的错误:
您也可以注意以下事项:
见Google Python Style Guide
命名对象的示例:
相关问题 更多 >
编程相关推荐