开发者

Error: Invalid Syntax on "def"

So I'm getting Invalid Syntax where it says def before the add_entry function. I have no idea why. I tried commenting out, and then there was the same error on a different function. I'm using Python 2.7.

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 = sa开发者_JS百科ve + 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


Your print statement in view_log has an extra [ It should be

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜