为什么这个功能不能在shell中打印?我不断得到这些东西:
<function terms at 0x025BD3D8>
def gdp_sections ():
file1 = open("GDP_Section1All_Hist1.csv" , 'r')
for i in range(7):
file1.readline()
a_tuple = []
line = file1.readline()
line = line.split(',')
year = line[22:43]
line = file1.readline()
line = line.split(',')
GDP_Change = line[22:43]
differences = []
for i in range (len(year)):
a_tuple = ((year[i]), (GDP_Change[i]))
differences.append(a_tuple)
file1 = open("GDP_Section1All_Hist2.csv" , 'r')
for i in range(7):
file1.readline()
a_tuple = []
line = file1.readline()
line = line.split(',')
year = line[4:48]
line = file1.readline()
line = line.split(',')
GDP_Change = line[4:48]
for i in range (len(year)):
a_tuple = ((year[i]), (GDP_Change[i]))
differences.append(a_tuple)
print(differences)
def terms():
file2 = open('the_correct_presidents.txt','r')
file2.readline()
for line in range(1,12):
line = file2.readline()
line = line.strip().split(',')
if len(line)>3:
del line[1]
name_of_president = line[0]
term = line[1].split('-')
year_started_term = int(term[0])
year_ended_term = int(term[1])
party = line[2]
print (line)
答案 0 :(得分:0)
你是如何调用terms
的?确保包括括号,否则您要求的是名为terms
的函数对象,它看起来就像您所看到的那样。函数是Python中的第一类对象,因此可以用作值并打印。
换句话说,你在shell上说这个吗?
>>> print(terms)
当你真的想要这个意思吗?
>>> print(terms())