Python 2.5 版本的 array.array.tostring()?
我在 GAE 上使用 2.5,使用 gdata python 模块中的一些加密模块。我可以在字符串上使用 hashAndSign,但该函数返回“B”无符号字符的 array.array。
我仍在尝试将它们组合在一起,但我现在遇到的一件事是得到 an:
array('B', [120, 231, 49, 2, 125, 143, 213, 14, 214, 66, 52, 11, 124, 154, 99, 179])
成为字符串表示形式,例如:
'x\xe71\x02}\x8f\xd5\x0e\xd6B4\x0b|\x9ac\xb3'
如何使数组成为这样的字符串?
我知道这是一件简单的事情,但它却难倒了我。
我需要这个,这样我就可以执行 .encode('base64') 发送到我的客户端应用程序,希望能够使用它来验证我签名的字符串。
I am using 2.5 on GAE using some of the Crypto modules from gdata python modules. I am able to use hashAndSign on a string, but the function returns an array.array of 'B' unsigned characters.
I'm still experimenting on getting it all together, but one thing I'm stumbling on now is getting an:
array('B', [120, 231, 49, 2, 125, 143, 213, 14, 214, 66, 52, 11, 124, 154, 99, 179])
to be a string representation like:
'x\xe71\x02}\x8f\xd5\x0e\xd6B4\x0b|\x9ac\xb3'
How can I get the array to be a string like that?
I know this is a simple thing, but it is stumping me.
I need this so I can do a .encode('base64') to send to my client app which hopefully will be able to use it to verify the string I signed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果由于某种原因 .tostring() 方法不可用——这让我认为这个数组与通常的 array.array 不同,因为 .tostring() 至少可以追溯到 python 2.4 - 然后
应该可以工作。
If for some reason the .tostring() method isn't available -- which makes me think that this array is different from the usual array.array, because .tostring() was around at least as far back as python 2.4 -- then
should work.
您的问题标题“Python 2.5 版本的 array.array.tostring()?”令人费解。
array.array
对象的tostring()
方法已经存在很长时间了:旁白:是的,没错,从前,
repr( )
是八进制,而不是十六进制。您在 Python 2.5 中实际尝试了什么?结果如何?将完整的堆栈跟踪和错误消息复制/粘贴到问题的编辑中。
Your question title "Python 2.5 version of array.array.tostring()?" is puzzling. The
tostring()
method ofarray.array
objects has been available for a very long time:Aside: Yes, that's right, once upon a time,
repr()
did octal, not hex.What did you actually try in Python 2.5? What was the outcome? Copy/paste the full stack trace and error message into an edit of your question.
或者只是 array.tostring 方法:
Or just
array.tostring
method: