'_csv.reader' object has no attribute 'count'
时间: 2023-09-15 14:20:01 浏览: 48
The error message you received indicates that you are trying to call the `count` method on a `_csv.reader` object, but this object does not have a `count` method.
`_csv.reader` is a built-in Python module for reading CSV files. It returns an iterator that generates rows of the CSV file as lists of strings. Since `_csv.reader` does not have a `count` method, you cannot call `count` on it.
If you want to count the number of rows in the CSV file, you can use a loop to iterate over the rows and keep a count variable. Here's an example:
```
import csv
with open('myfile.csv', 'r') as csvfile:
csvreader = csv.reader(csvfile)
count = 0
for row in csvreader:
count += 1
print("Number of rows:", count)
```
This code opens a CSV file named `myfile.csv`, creates a `_csv.reader` object from it, and then loops over the rows, incrementing the `count` variable for each row. Finally, it prints the total number of rows.