问题一 try: ..except..
python2的表达方式:
try:
....
except Exception, e:
print e
python3的表达方式:
try:
....
except Exception as e:
print (e)
问题二 from caffe.proto import caffe_pb2出错
python2:
from caffe.proto import caffe_pb2
python3:
try:
# Python3 will most likely not be able to load protobuf
from caffe.proto import caffe_pb2
except:
import sys
if sys.version_info >= (3, 0):
print("Failed to include caffe_pb2, things might go wrong!")
else:
raise
问题三 'module' object has no attribute 'urlopen'
官方解释:
a new urllib package was created. It consists of code from
urllib, urllib2, urlparse, and robotparser. The old
modules have all been removed. The new package has five submodules:
urllib.parse, urllib.request, urllib.response,
urllib.error, and urllib.robotparser. The
urllib.request.urlopen() function uses the url opener from
urllib2. (Note that the unittests have not been renamed for the
beta, but they will be renamed in the future.)
官方3.0版本已经把urllib2,urlparse等五个模块都并入了urllib中,也就是整合了。