一、WIN和Linux的路径表示不太一样,在两个平台分别使用os.getcwd()得到的结果分别是:”E:\PycharmProjects\untitled”,”/root”。WIN使用反斜杠\来分隔路径,而Linux使用/分隔。在使用到OS模块的时候,如果不是使用一些方法来动态获取路径的话,在移植的时候需要考虑到这个问题。
二、对于urllib模块,python3进行了一些修改。官方是这样说的:
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.)
也就是把urllib2、urlparse、robotparser这几个模块移除后加入urllib,然后urllib多了5个子模块:urllib.parse, urllib.request, urllib.response,
urllib.error, and urllib.robotparser。
别说了,一定是你空格和tab又乱用了。(一些编辑器会自动把tab转化成八个空格,手残党就用它们吧)
二、对于urllib模块,python3进行了一些修改。官方是这样说的:
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.)
也就是把urllib2、urlparse、robotparser这几个模块移除后加入urllib,然后urllib多了5个子模块:urllib.parse, urllib.request, urllib.response,
urllib.error, and urllib.robotparser。
比如:
params = urllib.urlencode(params).encode(encoding='UTF8')#python2
params = urllib.parse.urlencode(params).encode(encoding='UTF8')#python3
ret = urllib.urlopen(uri, params)#python2
ret = urllib.request.urlopen(uri, params)#python3
三、IndentationError: unexpected indent
别说了,一定是你空格和tab又乱用了。(一些编辑器会自动把tab转化成八个空格,手残党就用它们吧)