不会打印功能

时间:2015-10-26 01:16:56

标签: python printing try-catch except

我试图打印" print(tuple_list)"但我的程序继续我的除外并要求新的输入。有任何想法吗?感谢

def open_file():
    data=open("data_full.txt")
    return data


def process_file(data):
    user_month = input("Enter the number of months (N) which should be \
included in the list of warmest months: ")

    cnt = 0
    tuple_list = []
    header = data.readline()
    header = header.strip().split()
    #print(header)
    while True:    
        try:
            for line in data:
                cnt+= 1
                field = line.strip().split()
                line_list = [int(n) for n in field]
                #print(line_list)

                year = line_list[0]

                for i in range(1,13):
                    tuple_list.append(year,header[i],line_list[i])

                    print(tuple_list)      
            break

        except: 
            print("***Unusual circumstance. Try Again***")
            user_month = input("Enter the number of months (N) which should \
be included in the list of warmest months: ")

def main():
    while True:
        try:
            f=open_file()
            break
        except FileNotFoundError:
            print("Invalid file name. Try Again.")
    process_file(f)
    f.close()
main()

0 个答案:

没有答案