Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10805 > unrolled thread

attach cString to memoryview?

Started byPhlip <phlip2005@gmail.com>
First post2011-08-03 06:13 -0700
Last post2011-08-03 15:41 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  attach cString to memoryview? Phlip <phlip2005@gmail.com> - 2011-08-03 06:13 -0700
    Re: attach cString to memoryview? Peter Otten <__peter__@web.de> - 2011-08-03 15:41 +0200

#10805 — attach cString to memoryview?

FromPhlip <phlip2005@gmail.com>
Date2011-08-03 06:13 -0700
Subjectattach cString to memoryview?
Message-ID<4232b39e-e07c-4e12-92e3-1e7b035422a6@a2g2000prf.googlegroups.com>
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

[toc] | [next] | [standalone]


#10806

FromPeter Otten <__peter__@web.de>
Date2011-08-03 15:41 +0200
Message-ID<j1bj73$a33$1@solani.org>
In reply to#10805
Phlip wrote:

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

> The Subject line problem refers to how to get rid of this:
> 
>     AttributeError: 'cStringIO.StringO' object
>                                        has no attribute 'fileno'

What's wrong with subprocess.PIPE?

>>> import subprocess as sp                                           
>>> p = sp.Popen(["ls", "/usr/lib/python2.6"], stdout=sp.PIPE)
>>> print p.communicate()[0]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web