Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 979359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:12:27+00:00 2026-05-16T04:12:27+00:00

There is a buffer type in Python, but how can I use it? In

  • 0

There is a buffer type in Python, but how can I use it?

In the Python documentation about buffer(), the description is:

buffer(object[, offset[, size]])

The object argument must be an object that supports the buffer call interface (such as strings, arrays, and buffers). A new buffer object will be created which references the object argument. The buffer object will be a slice from the beginning of object (or from the specified offset). The slice will extend to the end of object (or will have a length given by the size argument).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:12:28+00:00Added an answer on May 16, 2026 at 4:12 am

    An example usage:

    >>> s = 'Hello world'
    >>> t = buffer(s, 6, 5)
    >>> t
    <read-only buffer for 0x10064a4b0, size 5, offset 6 at 0x100634ab0>
    >>> print t
    world
    

    The buffer in this case is a sub-string, starting at position 6 with length 5, and it doesn’t take extra storage space – it references a slice of the string.

    This isn’t very useful for short strings like this, but it can be necessary when using large amounts of data. This example uses a mutable bytearray:

    >>> s = bytearray(1000000)   # a million zeroed bytes
    >>> t = buffer(s, 1)         # slice cuts off the first byte
    >>> s[1] = 5                 # set the second element in s
    >>> t[0]                     # which is now also the first element in t!
    '\x05'
    

    This can be very helpful if you want to have more than one view on the data and don’t want to (or can’t) hold multiple copies in memory.

    Note that buffer has been replaced by the better named memoryview in Python 3, though you can use either in Python 2.7.

    Note also that you can’t implement a buffer interface for your own objects without delving into the C API, i.e. you can’t do it in pure Python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 476k
  • Answers 476k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try exec 2> /tmp/error.log. From the manual: exec [  -c… May 16, 2026 at 4:57 am
  • Editorial Team
    Editorial Team added an answer For simple cases, you can specify custom error messages class… May 16, 2026 at 4:57 am
  • Editorial Team
    Editorial Team added an answer To prevent this kind of warning, have the function return… May 16, 2026 at 4:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.