2010-11-02 71 views
0

我有兩個腳本一個工作,另一個具有給變量賦予正確值的函數。導入其他不能正常工作的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

回答

1

您需要的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