在Python 2.7我可以像這樣創建一個字符數組:python 3中的字符數組?
#Python 2.7 - works as expected
from array import array
x = array('c', 'test')
但Python 3'c'
不再可用的類型代碼。如果我想要一系列角色,我該怎麼做? 'u'
類型也正在被刪除。
#Python 3 - raises an error
from array import array
x = array('c', 'test')
TypeError: cannot use a str to initialize an array with typecode 'c'
無論你的代碼示例是相同的。 –
@DawidFerenczy是的。一個是Python 2.7,一個是Python 3.4。 –