Can I use cStringIO the same as StringIO?

后端 未结 2 1431
深忆病人
深忆病人 2021-02-07 06:59

I did this:

import cStringIO.StringIO as StringIO

And I realize I\'ve been using it everywhere. Is that fine? Is it treated the same as String

2条回答
  •  时光说笑
    2021-02-07 07:47

    Nor can you set attributes on a cStringIO.StringIO instance:

    >>> from cStringIO import StringIO
    >>> s = StringIO()
    >>> s.name = 'myfile'
    Traceback (most recent call last):
      File "", line 1, in 
    AttributeError: 'cStringIO.StringO' object has no attribute 'name'
    

    Several libraries depend on File-like objects having either a name or content_type attribute, so cStringIO.StringIO does not work in these instances.

提交回复
热议问题