![](https://secure.gravatar.com/avatar/02a09c808befe98964f1441430fb9fb4.jpg?s=120&d=mm&r=g)
On page: http://docs.python.org/3.0/library/csv.html Under Examples: ---- The simplest example of reading a CSV file: import csv reader = csv.reader(open("some.csv", "rb")) for row in reader: print(row) ---- Code works in python 2, but in python 3, it throws error: ---- Traceback (most recent call last): File "WeeklyDepletionParser.py", line 3, in <module> for row in reader: _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) ---- Fix was straightforward to change parameter "rb" to "rt". I am running: Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Owen
![](https://secure.gravatar.com/avatar/3c46e59585526b90c088845402bc8407.jpg?s=120&d=mm&r=g)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 06.08.2013 08:47, schrieb Owen Johnson:
On page:
http://docs.python.org/3.0/library/csv.html
Under Examples:
---- The simplest example of reading a CSV file:
import csv reader = csv.reader(open("some.csv", "rb")) for row in reader: print(row) ----
Code works in python 2, but in python 3, it throws error:
---- Traceback (most recent call last): File "WeeklyDepletionParser.py", line 3, in <module> for row in reader: _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) ----
Fix was straightforward to change parameter "rb" to "rt".
I am running:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Hi Owen, please update your links to use the most recent version of the docs; the /3.0/ docs are not updated anymore. The current Python 3 docs at http://docs.python.org/3/library/csv.html are already correct. cheers, Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.21 (GNU/Linux) iEYEARECAAYFAlJRJpkACgkQN9GcIYhpnLA36gCcCXd3O0LQWcJtR6yrMiVgh028 EaMAoKQ744RFrkOpigRYoxHrkueH+DlP =LJlv -----END PGP SIGNATURE-----
participants (2)
-
Georg Brandl
-
Owen Johnson