未定义导入的变量
Imported Variable not defined
目前正在尝试将我的代码从 "Original Program" 导入到 "Import",该代码独立运行良好。我收到错误 "Date is not defined"。我假设错误与全局变量有关。我知道这一点,并花了一些时间试图自己解决这个问题,但无济于事。任何帮助表示赞赏:)
**Original Program**
def validDate(date, month, day):
months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
leapyear = ((date % 4) == 0) and ((date % 100) != 0) or ((date % 4) ==
0) and ((date % 100) == 0) and ((date % 4000) == 0)
if leapyear:
days[1] += 1
valid = (day <= days[months.index(month)] and day > 0 and (1753 <=
date))
print(valid)
date = int(input("Enter year: "))
month = int(input("Enter month: "))
day = int(input("Enter day: "))
validDate(date, month, day)
**Import**
from libHWDate import validDate
validDate(date, month, day)
删除导入命令
从 libHWDate 导入 validDate
目前正在尝试将我的代码从 "Original Program" 导入到 "Import",该代码独立运行良好。我收到错误 "Date is not defined"。我假设错误与全局变量有关。我知道这一点,并花了一些时间试图自己解决这个问题,但无济于事。任何帮助表示赞赏:)
**Original Program**
def validDate(date, month, day):
months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
leapyear = ((date % 4) == 0) and ((date % 100) != 0) or ((date % 4) ==
0) and ((date % 100) == 0) and ((date % 4000) == 0)
if leapyear:
days[1] += 1
valid = (day <= days[months.index(month)] and day > 0 and (1753 <=
date))
print(valid)
date = int(input("Enter year: "))
month = int(input("Enter month: "))
day = int(input("Enter day: "))
validDate(date, month, day)
**Import**
from libHWDate import validDate
validDate(date, month, day)
删除导入命令 从 libHWDate 导入 validDate