I took some sample code that was made in the django version 1.8.4, and like Python 2.7 when transferred to 3 python all flown away and produced such an error, how to fix it?
\lib\site-packages\config.py", line 91, in <module>
from types import StringType, UnicodeType
ImportError: cannot import name 'StringType'
one piece of code where using stringtype (config.py)(in 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))
There is no StringType
in Python3.
Try this instead:
from types import *
x=type('String')
To check the type of an object use:
type(x) is str
which gives : True
in the given case.
Also, alter you code as suggested in the question comments by iFlo : https://docs.python.org/3/howto/pyporting.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With