rougier/numpy-100

Problem 54 error

yiyuezhuo opened this issue · 2 comments

For origin code, I encounter the error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-234023c5571a> in <module>()
      5                 6,  ,  , 7, 8\n
      6                  ,  , 9,10,11\n""")
----> 7 Z = np.genfromtxt(s, delimiter=",", dtype=np.int)
      8 print(Z)

C:\Users\yiyuezhuo\Anaconda3\lib\site-packages\numpy\lib\npyio.py in genfromtxt(fname, dtype, comments, delimiter, skip_header, skip_footer, converters, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise, max_rows)
   1480                     first_line = (
   1481                         asbytes('').join(first_line.split(comments)[1:]))
-> 1482             first_values = split_line(first_line)
   1483     except StopIteration:
   1484         # return an empty array if the datafile is empty

C:\Users\yiyuezhuo\Anaconda3\lib\site-packages\numpy\lib\_iotools.py in _delimited_splitter(self, line)
    217     def _delimited_splitter(self, line):
    218         if self.comments is not None:
--> 219             line = line.split(self.comments)[0]
    220         line = line.strip(asbytes(" \r\n"))
    221         if not line:

TypeError: Can't convert 'bytes' object to str implicitly

I read numpy document, and I found

Mote that generators must return byte strings in Python 3k.

However, when I change StringIO to BytesIO and add prefix b before the string. I can get true result.

What python version do you use?

Python 3.5.2.

Oh, I considered that io module only existed in python3, but now I have found both StringIO and io module coexisted in python2. So I misunderstant that this code is compatible for python3. It looks actually that it's for python2 specially. This issue can be looked as tiny python 3 compatible problem.