2011-07-30 214 views
1

所以我得到語法無效它說在def add_entry函數之前。我不知道爲什麼。我嘗試了註釋,然後在不同的功能上出現了相同的錯誤。我正在使用Python 2.7。錯誤:「def」語法無效

date,number = 0,1 
month,day,year = 1,2,0 
from datetime import datetime 

def home(): 
    option = '' 
    option = raw_input('Press ENTER to view log or input anything to add entries: ') 
    print '\n' 
    if option == '': 
     view_log() 
    else: 
     add_entry() 

def view_log(): 
    log_a = open('storage.txt', 'r') 
    log_b = log_a.read() 
    for line in log_b: 
     print line[date[month]],line[date[day]],line[date[[year]],line[number] 

def add_entry(): 
    old_entry = open('storage.txt', 'r') 
    save = '' 
    for line in old_entry: 
     save = save + line 
    new_entry = open('storage.txt','w') 
    new = input_entry() 
    save = save + str(new) + '\n' 
    new_entry.write(save) 

def input_entry(): 
    n_date = get_date() 
    print 'Todays date is: %s/%s/%s' %(n_date[month],n_date[day],n_date[year]) 
    n_number = raw_input('What was todays number? ') 
    return (n_date,n_number) 

def get_date(): 
    time_a = datetime.now() 
    time_b = str(time_a) 
    time_c = time_b.split(' ') 
    time_d = time_c[0].split('-') 
    time_e = tuple(time_d) 
    return time_e 
+10

臨提示:當你得到一個語法錯誤,總是看前行了。 –

回答

10

view_log您的打印語句中有一個額外的[ 應該

print line[date[month]],line[date[day]],line[date[year]],line[number]