attach cString to memoryview?

Phlip phlip2005 at gmail.com
Wed Aug 3 09:13:24 EDT 2011


HypoNt;

My ulterior motive is the perfect command spawner:

def call_4(cmd):

    import cStringIO

        #   memoryview type
        #   New in version 2.7.
    v = memoryview('abcefg')

    q = cStringIO.StringIO()
    p = Popen(cmd, shell=True, stdout=q, bufsize=4096)

    def check_me():
                                   # consider: examine p or v here
        return q.read()

    return check_me

# check_it = call_4('ls')
# check_it()

assert 'fabfile.py' in call_4('ls')()

# Look, ma!  No self.!

The Subject line problem refers to how to get rid of this:

    AttributeError: 'cStringIO.StringO' object
                                       has no attribute 'fileno'

To give it one, plug in a memoryview, right?

Pencils down in 15 minutes, okay? Go! While I'm googling up a more
mundane (and less performant) solution with a normal file...

Distractingly yrs-

--
  Phlip
  http://bit.ly/ZeekLand



More information about the Python-list mailing list