setuptools - python 3 and the file object -
i looking @ using setup.py automatically generate python 3 code python 2 sources using 'use_2to3' attribute. setup.py script includes following statement:
version = none file('version','rt') ff: version = ff.read().lstrip().rstrip() print("version %s" % (version) ) when type 'python3 setup.py build' error:
traceback (most recent call last): file "setup.py", line 18, in <module> file('version','rt') ff: nameerror: name 'file' not defined which understand correct file object no longer exists , should change 'open()'.
the concern '2to3' utility not detect , leaves code untouched. unfortunately use idiom throughout code.
is bug in '2to3' ?
use open instead of file.
it tempting use file() instead of open() in python 2.x -- oo background. file() call resembled calling constructor creation of file object. however, recommended use open() function instead. may reason why 2to3 not solve case.
in python 3, file unknown. file objects of _io.textiowrapper class:
>>> f = open('a.txt', 'w') >>> type(f) <class '_io.textiowrapper'> >>> f.__class__.__name__ 'textiowrapper'
Comments
Post a Comment