我拿了一些在django版本1.8.4中制作的示例代码,和Python 2.7一样,当转移到3 python时都飞走了并产生了这样的错误,如何修复它?
\lib\site-packages\config.py", line 91, in <module>
from types import StringType, UnicodeType
ImportError: cannot import name 'StringType'
Run Code Online (Sandbox Code Playgroud)
使用stringtype(config.py)的一段代码(在site-packages中)
def writeValue(self, value, stream, indent):
if isinstance(self, Mapping):
indstr = ' '
else:
indstr = indent * ' '
if isinstance(value, Reference) or isinstance(value, Expression):
stream.write('%s%r%s' % (indstr, value, NEWLINE))
else:
if (type(value) is StringType): # and not isWord(value):
value = repr(value)
stream.write('%s%s%s' % (indstr, value, NEWLINE))
Run Code Online (Sandbox Code Playgroud)
StringTypePython3中没有.
试试这个:
from types import *
x=type('String')
Run Code Online (Sandbox Code Playgroud)
要检查对象的类型,请使用:
type(x) is str
Run Code Online (Sandbox Code Playgroud)
这给出了:True在给定的情况下.
另外,按照iFlo的问题评论中的建议更改您的代码:https://docs.python.org/3/howto/pyporting.html
| 归档时间: |
|
| 查看次数: |
5284 次 |
| 最近记录: |