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 8255525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:33:27+00:00 2026-06-08T01:33:27+00:00

How can I read int from a file? I have a large(512MB) txt file,

  • 0

How can I read int from a file? I have a large(512MB) txt file, which contains integer data as:

0 0 0 10 5 0 0 140
0 20 6 0 9 5 0 0

Now if I use c = file.read(1), I get only one character at a time, but I need one integer at a time. Like:

c = 0
c = 10
c = 5
c = 140 and so on...

Any great heart please help. Thanks in advance.

  • 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-08T01:33:29+00:00Added an answer on June 8, 2026 at 1:33 am

    Here’s one way:

    with open('in.txt', 'r') as f:
      for line in f:
        for s in line.split(' '):
          num = int(s)
          print num
    

    By doing for line in f you are reading bit by bit (using neither read() all nor readlines). Important because your file is large.

    Then you split each line on spaces, and read each number as you go.

    You can do more error checking than that simple example, which will barf if the file contains corrupted data.

    As the comments say, this should be enough for you – otherwise if it is possible your file can have extremely long lines you can do something trickier like reading blocks at a time.

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

Sidebar

Related Questions

I have a large data file, which is zipped, and approximately 20MB. When it's
I have read several forums but can't find the solution to this. int sIndex
I have a htm file can i read it as UTF-8 formatted file without
How it's possible to read characters from file without loosing the spaces? I have
I have a large file, with 1.8 million rows of data, that I need
How can I read the contents of a file if I have to use
I have a situation where I read data from a struct and keep appending
I have a 100 GB text file, which is a BCP dump from a
I have to read tags from an FLV file and there are three chars
I am trying to read Data from a Text file & storing it inside

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.