AttributeError:“ builtin_function_or_method”对象没有属性“ csv”

时间:2018-09-22 04:53:43

标签: python

我无法读取功能中的csv文件!!

JSONDATA:

{
  "Channel": {
    "SalesChaneel": {
      " Step1:salesChannel": {
        "ChannelList1": {
          "Lis1": "Vlaue1",
          "Lis2": "Vlaue1",
          "Lis3": "Vlaue1"
        },
        "ChannelList2": {
          "Lis4": "Vlaue2",
          "Lis5": "Vlaue2",
          "Lis6": "Vlaue2"
        }
      }
    },
    "SalesChanee2": {
      " Step2:salesChannel": {
        "ChannelList3": {
          "Lis8": "Vlaue1",
          "Lis9": "Vlaue1",
          "Lis10": "Vlaue1"
        },
        "ChannelList4": {
          "Lis11": "Vlaue2",
          "Lis12": "Vlaue2",
          "Lis13": "Vlaue2"
        }
      }
    }
  }
}

---------------------

以及在调用我的函数时:

  def calculate_averages(input_file_name, output_file_name):
with (open(input_file_name,'r')) as fin:
    reader=csv.reader(fin)
        for row in reader:
        name=row[0]
        grades=list()
        for grade in row[1:]:
            grades.append(float(grade))
            with open(output_file_name,'w') as f:
             for item in grades:

              f.write("%s\n" % item)

f.close()
return f

我有此错误:

 calculate_averages(input.csv ,output.csv)

但是我已经创建了input.csv文件和output.csv文件!!! 我在做什么错??

1 个答案:

答案 0 :(得分:1)

将文件名括在引号中,如下所示:

calculate_averages('input.csv', 'output.csv')