2016-04-13 3 views
-1
if "A" in columns and int(columns[5]) < int(columns[3]): 
      print(columns) 
      print (columns[3]) - (columns[5]) 

私はここで何が間違っていますか?私は最近、コーディングを始めました。.txtファイルから2つの値を取り除くにはどうすればいいですか

これは完全なコードです:

import csv 

FILE_NAME = "paintingJobs.txt" #I use this so that the file can be used easier 
COL_HEADERS = ['Number', 'Date', 'ID', 'Total', 'Status', 'Paid'] 
NUM_COLS = len(COL_HEADERS)#This will insure that the header of each column fits into the length of the data 

# read file once to determine maximum width of data in columns 
with open(FILE_NAME) as f: 
    reader = csv.reader(f, delimiter=',') 
    # determine the maximum width of the data in each column 
    max_col_widths = [len(col_header) for col_header in COL_HEADERS] 
    for columns in reader: 
     for i, col in enumerate(columns): 
      if "A" in columns and int(columns[5]) < int(columns[3]): 
       max_col_widths[i] = max(max_col_widths[i], len(repr(col))) 
    # add 1 to each for commas 
    max_col_widths = [col_width+1 for col_width in max_col_widths] 

# read file second time to display its contents with the headers 
with open(FILE_NAME) as f: 
    reader = csv.reader(f, delimiter=',') 
    # display justified column headers 
    print(' ' + ' '.join(col_header.ljust(max_col_widths[i]) 
          for i, col_header in enumerate(COL_HEADERS))) 
    # display justified column data 
    for columns in reader: 
     if "A" in columns and int(columns[5]) < int(columns[3]): 
      print(columns) 
      print (columns[3]) - (columns[5])` 

そして、これは私が取得エラーです:

line 72, in Option_B 
print (columns[3]) - (columns[5]) 

TypeError: unsupported operand type(s) for -: 'NoneType' and 'str'

+0

サンプル入力、出力、試したこと、何を返すあなたは期待しています。 – mikeb

+0

エラーメッセージが表示されますか?あれば、何ですか?あなたは間違った結果を得ていますか?列とは何ですか?あなたはどんな結果を期待しましたか?あなたはPython 2を使用していますか? – cdarke

+0

Ok投稿を更新しました –

答えて

0

あなたが印刷する前に、あなたはおそらく、あなたの数字を変換する必要があります。

print("The result: ") 
print(int(column[3]) - int(column[5])) 
関連する問題