【发布时间】:2011-06-28 16:44:03
【问题描述】:
如何在 Python 中实现以下代码(ActionScript)?
var bytes:ByteArray = new ByteArray();
var text:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus etc.";
bytes.writeUTFBytes(text); // write the text to the ByteArray
trace("The length of the ByteArray is: " + bytes.length); // 70
bytes.position = 0; // reset position
while (bytes.bytesAvailable > 0 && (bytes.readUTFBytes(1) != 'a')) {
//read to letter a or end of bytes
}
if (bytes.position < bytes.bytesAvailable) {
trace("Found the letter a; position is: " + bytes.position); // 23
trace("and the number of bytes available is: " + bytes.bytesAvailable); // 47
}
我看过 bytearray 并认为这段代码涵盖了前 4 行:
text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Vivamus etc."
bytes = bytearray(text)
print "The length of the ByteArray is: " + str(len(bytes))
从第 5 行开始,我不确定 Python 的等价物。例如,我找不到 position 方法,但可以使用 bytes[i],其中 i 是我要检索的字节数组中的位置。
谢谢。
【问题讨论】:
标签: python actionscript bytearray