Python AttributeError: _csv.reader Object Has No Attribute Next

Python AttributeError: _csv.reader Object Has No Attribute Next

The CSV format is one of the most used formats in spreadsheets and databases. The Python language has the csv module that provides classes to read and write data in CSV format.

Attributes are values that are related to an object or a class. An AttributeError occurs in Python when you call an attribute of an object whose type is not supported by the method.

For instance, using the split() method on a file object returns an AttributeError because the file objects do not support the split() method.

This tutorial will teach you to fix the AttributeError: '_csv.reader' object has no attribute 'next' in Python.

Fix the AttributeError: '_csv.reader' object has no attribute 'next' Error in Python

The csv.reader object is an iterator. The next() method is available in the csv.reader object and returns the next row of the iterable object.

import csv

with open(csvfile) as f:
	reader = csv.reader(f, delimiter=',', quotechar='"', skipinitialspace=True)
	header = reader.next()
	f.close()

Output:

line 5, in <module>
    header = reader.next()
AttributeError: '_csv.reader' object has no attribute 'next'

But in Python 3, you have to use the built-in function next(reader) instead of the reader.next() method.

import csv

with open(csvfile) as f:
	reader = csv.reader(f, delimiter=',', quotechar='"', skipinitialspace=True)
	header = next(reader)
	f.close()

With this, the AttributeError should be solved in Python. We hope you found this article helpful.

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

Related Article - Python AttributeError

  • AttributeError: Int Object Has No Attribute
  • AttributeError: __Exit__ in Python
  • AttributeError: 'NoneType' Object Has No Attribute 'Text' in Python
  • Python AttributeError: '_io.TextIOWrapper' Object Has No Attribute 'Split'
  • Related Article - Python Error

  • Python PermissionError: [WinError 5] Access Is Denied
  • Python TypeError: 'DataFrame' Object Is Not Callable
  • Python TypeError: Can't Convert 'List' Object to STR
  • Local Variable Referenced Before Assignment Error in Python
  • Python Handling Socket.Error: [Errno 104] Connection Reset by Peer
  • Python Is Not Recognized in Windows 10