這是我的代碼。在第一個def函數中,我讓它返回column_choose,並且我想在第二個def函數(get_data_list)中使用column_choose的值。我能做什麼?我已經嘗試了很多次。但IDLE總是顯示:全局名稱「column_choose」未定義。如何在第二個函數中使用第一個函數的返回值?
如何在第二個函數中使用column_choose的值? 順便說一下,我使用python 3.2
def get_column_number():
while True:
column_choose = input('What column:')
if column_choose == '1' or column_choose == '2' or column_choose == '3' or column_choose == '4' or column_choose == '5' or column_choose == '6':
column_choose = int(column_choose)
return column_choose
break
else:
print('bad column number, try again')
def get_data_list(column_number):
new_column_number = column_number.split(',')
date_column = new_column_number[0]
choose_column = new_column_number[column_choose-1]
return result
def main():
#Call get_input_descriptor
get_input_descriptor()
#Call get_column_number
get_column_number()
file_obj = open("table.csv", "r")
for column_number in file_obj:
column_number = (column_number.strip())
result = get_data_list(column_number)
print(result)
file_obj.close()
main()
你應該修改你的代碼,縮進錯誤 – 2013-02-25 03:47:17