Skip to content

Commit

Permalink
MAINT: don't use open(.., 'U') in Python 3.x, is deprecated.
Browse files Browse the repository at this point in the history
This is default behavior in 3.x; in 2.x open() doesn't have a `newline`
kw.  So make code Python-version-specific.
  • Loading branch information
rgommers authored and juliantaylor committed Dec 30, 2013
1 parent e49876f commit 0dfd162
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions numpy/lib/npyio.py
Expand Up @@ -716,8 +716,10 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
elif fname.endswith('.bz2'):
import bz2
fh = iter(bz2.BZ2File(fname))
else:
elif sys.version_info[0] == 2:
fh = iter(open(fname, 'U'))
else:
fh = iter(open(fname))
else:
fh = iter(fname)
except TypeError:
Expand Down Expand Up @@ -1321,7 +1323,10 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
own_fhd = False
try:
if isinstance(fname, basestring):
fhd = iter(np.lib._datasource.open(fname, 'rbU'))
if sys.version_info[0] == 2:
fhd = iter(np.lib._datasource.open(fname, 'rbU'))
else:
fhd = iter(np.lib._datasource.open(fname, 'rb'))
own_fhd = True
else:
fhd = iter(fname)
Expand Down

0 comments on commit 0dfd162

Please sign in to comment.