0 python
给定一个函数返回的多字符串我正在使用表单的ctypes访问:
"the quick brown fox\x00jumped over the lazy\00programmer\00\00"
Run Code Online (Sandbox Code Playgroud)
将此转换为这样的python列表的最佳方法是什么:
["the quick brown fox", "jumped over the lazy", "programmer"]
Run Code Online (Sandbox Code Playgroud)
我尝试使用foo.split('\ x00'),但这不起作用.
特定
sentence = "the quick brown fox\x00jumped over the lazy\00programmer\00\00"
[phrase for phrase in sentence.split("\x00") if phrase != ""]
Run Code Online (Sandbox Code Playgroud)
编辑
直接从马的嘴里:
>>> sentence = "the quick brown fox\x00jumped over the lazy\00programmer\00\00"
>>> [phrase for phrase in sentence.split('\x00') if phrase != ""]
['the quick brown fox', 'jumped over the lazy', 'programmer']
Python 2.6.1 (r261:67515, Jul 9 2009, 14:20:26)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
914 次 |
| 最近记录: |