繁体   English   中英

错误:“ def”语法无效

[英]Error: Invalid Syntax on “def”

所以我在add_entry函数之前得到了def的无效语法 我不知道为什么。 我尝试注释掉,然后在不同的函数上出现相同的错误。 我正在使用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 = 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

您在view_log中的打印语句有一个额外的[应该是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM