Re: raw string from mmap.read() possible?

Discussion in 'Python' started by Dan Jones, Nov 10, 2003.

  1. Dan Jones

    Dan Jones Guest

    On Sun, 2003-11-09 at 17:25, Fredrik Lundh wrote:
    > Dan Jones wrote:
    >
    > > yuvframe = mmap.read(WIDTH*HEIGHT*3)
    > > rgbframe = yuv.yuv2rgb(WIDTH, HEIGHT, yuvframe)
    > >
    > > At this point it gives a typeerror: argument 3 must be string without
    > > null bytes, not str.

    >
    > your C extension uses the "s" marker for the third argument. don't
    > do that if you plan to pass in null bytes; use "s#" instead.
    >
    > see the documentation for details:
    >
    > http://www.python.org/doc/current/api/arg-parsing.html
    >
    > "s" (string or Unicode object) [char *]
    >
    > Convert a Python string or Unicode object to a C pointer to a character
    > string. /.../ The C string is NUL-terminated. The Python string must not
    > contain embedded NUL bytes; if it does, a TypeError exception is raised.
    > /.../
    >
    > "s#" (string, Unicode or any read buffer compatible object) [char *, int]
    >
    > This variant on "s" stores into two C variables, the first one a pointer to
    > a character string, the second one its length. In this case the Python
    > string may contain embedded null bytes. /.../
    >
    > > but if I send it a raw string it doesn't complain:
    > >
    > > rgbframe = yuv.yuv2rgb(WIDTH, HEIGHT, r"\0\0\0\0")
    > >
    > > I'm assuming this is happening because C interprets NULL as the end of
    > > the string. Is there a way to get a raw string directly from the
    > > mmap.read() call or do I have to do a conversion after the read?

    >
    > when you've fixed the C extension, I suggest reading the section
    > on "raw strings" in the language reference:
    >
    > http://www.python.org/doc/current/ref/strings.html
    >
    > </F>


    That worked, thanks! I was looking for a solution on the wrong end.

    Dan
    Dan Jones, Nov 10, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. junky_fellow

    mmap vs read/write

    junky_fellow, Feb 25, 2004, in forum: C Programming
    Replies:
    3
    Views:
    891
    Derk Gwen
    Feb 25, 2004
  2. Dan Jones

    raw string from mmap.read() possible?

    Dan Jones, Nov 9, 2003, in forum: Python
    Replies:
    1
    Views:
    322
    David M. Wilson
    Nov 9, 2003
  3. Fredrik Lundh

    Re: raw string from mmap.read() possible?

    Fredrik Lundh, Nov 9, 2003, in forum: Python
    Replies:
    0
    Views:
    392
    Fredrik Lundh
    Nov 9, 2003
  4. Phd
    Replies:
    3
    Views:
    1,125
    Steven Bethard
    Dec 6, 2004
  5. Neal Becker

    mmap only supports string

    Neal Becker, Jan 8, 2009, in forum: Python
    Replies:
    1
    Views:
    330
    Aaron Brady
    Jan 8, 2009
Loading...

Share This Page