导入其他不能正常工作的python文件函数

导入其他不能正常工作的python文件函数

问题描述:

我有两个脚本一个工作,另一个具有给变量赋予正确值的函数。导入其他不能正常工作的python文件函数

while True: 
    day = raw_input("Please Enter The Day: ") 
    month = raw_input("Please Enter The Month: ") 
    year = raw_input("Please Enter The Year: ") 

    if day.isdigit(): 
     if day > 0: 
      correctcheck = "1" 
     else: 
      print "You Did Not Enter A Valid Day" 
      errormsg = "1" 
      break 
    else: 
     print "You Did Not Enter A Valid Day" 
     errormsg = "1" 
     break 

    if month.isdigit(): 
     if month > 0: 
      correctcheck = "2" 
     else: 
      print "You Did Not Enter A Valid Month" 
      errormsg = "1" 
      break 
    else: 
     print "You Did Not Enter A Valid Month" 
     errormsg = "1" 
     break 

    if year.isdigit(): 
     if year > 0: 
      correctcheck = "3" 
     else: 
      print "You Did Not Enter A Valid Year" 
      errormsg = "1" 
      break 
    else: 
     print "You Did Not Enter A Valid Year" 
     errormsg = "1" 
     break 

    if correctcheck == "3": 
     COUNT_help.months(months = month) 
     print month 
     print months 

SCRIPT 2:无论如何,我呼吁利用脚本(1)

SCRIPT 1(与去年LINE COUNT_help.months()问题的一个参数(2)脚本函数时收到以下错误:

jan = 1 
feb = 32 
mar = 60 
apr = 91 
may = 121 
jun = 152 
jul = 182 
aug = 213 
sep = 244 
obr = 274 
nov = 305 
dec = 335 

def months(months = ""): 
    if months == "1": 
     months = jan 
     return months 
    if months == "2": 
     months = feb 
     return months 
    if months == "3": 
     months = mar 
     return months 
    if months == "4": 
     months = apr 
     return months 
    if months == "5": 
     months = may 
     return months 
    if months == "6": 
     months = jun 
     return months 
    if months == "7": 
     months = jul 
     return months 
    if months == "8": 
     months = aug 
     return months 
    if months == "9": 
     months = sep 
     return months 
    if months == "10": 
     months = obr 
     return months 
    if months == "11": 
     months = nov 
     return months 
    if months == "12": 
     months = dec 
     return months 
+0

和什么问题?你的文件又如何连接?进口声明在哪里? – SilentGhost 2010-11-02 17:42:59

+0

回溯(最近通话最后一个): 文件 “C:\用户\奥马尔\桌面\ COUNT.py” 60行,在 COUNT_help.months(月=月) AttributeError的: '模块' 对象有没有属性'months' – DonJuma 2010-11-02 17:47:10

+2

你是如何导入第二个脚本的? – user225312 2010-11-02 17:47:56

您需要的COUNT_help.months(months = month)结果某处分配。另外寻找到datetime库。

if correctcheck == "3": 
    months = COUNT_help.months(months = month) 
    print month 
    print months 
+0

返回这个:Traceback(最近一次调用最后一个): 文件“C:\ Users \ Omar \ Desktop \ COUNT.py”,行60, months = COUNT_help.months(months = month) AttributeError:'module'object has no attribute'months – DonJuma 2010-11-02 17:49:32

+0

@Mthethew您是否在'COUNT_help.py'中设置了__all__变量?此外,请在上面包含您的原始'import'声明。 – user470379 2010-11-02 17:51:23

+0

我使用进口COUNT_help和不使用'__all__'我得到了使用1__all__ – DonJuma 2010-11-02 17:53:53