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

  • SEARCH
  • Home
  • 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 8405123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:46:13+00:00 2026-06-09T22:46:13+00:00

I wrote a program that uses bitarray 0.8.0 to write bits to a binary

  • 0

I wrote a program that uses bitarray 0.8.0 to write bits to a binary file. I would like to add a header to this binary file to describe what’s inside the file.

My problem is that I think the method “fromfile” of bitarray necessarily starts reading the file from the beginning. I could make a workaround so that the reading program gets the header and then rewrite a temporary file containing only the binary portion (bitarray tofile), but it doesn’t sound too efficient of an idea.

Is there any way to do this properly?

My file could look something like the following where clear text is the header and binary data is the bitarray information:

…{(0, 0): ‘0’}{(0, 0): ‘0’}{(0, 0): ‘0’}���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������…

Edit:

I tried the following after reading the response:

bits = ""
b = bitarray()
with open(Filename, 'rb') as file:
    #Get header
    byte = file.read(1)
    while byte != "":
        # read header
        byte = file.read(1)
    b.fromfile(file)
    print b.to01()
    print "len(b.to01())", len(b.to01())

The length is 0 and the print of “to01()” is empty.
However, the print of the header is fine.

  • 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-06-09T22:46:14+00:00Added an answer on June 9, 2026 at 10:46 pm

    My problem is that I think the method “fromfile” of bitarray necessarily starts reading the file from the beginning.

    This is likely false; it, like most other file read routines, probably starts at the current position within the file, and stops at EOF.

    EDIT:

    From the documentation:

    fromfile(f, [n])

    Read n bytes from the file object f and append them to the bitarray interpreted as machine values. When n is omitted, as many bytes are read until EOF is reached.

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

Sidebar

Related Questions

I'd like to write a Haskell program that uses GADTs interactively on a platform
The problem is this: I wrote a simple program that uses FFMPEG. compile as
I wrote a program that uses builtin function bin(), but this function is new
I wrote a program, that uses a shared library installed on my system. This
I wrote a batch file that uses the program curl.exe to download a database
This is question about Objective-C. I wrote the program that uses regular expression with
I wrote a C# program that uses the mouse and it works perfectly. I
I wrote a program on Ubuntu 11.04 that uses freeglut. It worked fine. Then
I need to write a program that uses matrix multiplication to rotate an image
I tried to write a program that uses threads, but couldn't understand the o/p.

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.