ill*_*ant 7 c# python memorystream
MemoryStreamPython中是否存在一些C#模拟(可以让我将某些源的二进制数据直接写入内存)?我将如何使用它?
如果您使用 Python >= 3.0 并尝试了Adam's answer,您会注意到import StringIO或import cStringIO两者都给出了导入错误。这是因为 StringIO现在是io模块的一部分。
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import StringIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'StringIO'
>>> # Huh? Maybe this will work...
...
>>> import cStringIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'cStringIO'
>>> # Whaaaa...?
...
>>> import io
>>> io.StringIO
<class '_io.StringIO'>
>>> # Oh, good!
...
Run Code Online (Sandbox Code Playgroud)
您可以使用StringIO就好像它是一个普通的Python文件:write(),close(),和所有爵士乐,另外还有getvalue()检索字符串。
| 归档时间: |
|
| 查看次数: |
4046 次 |
| 最近记录: |