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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:00:24+00:00 2026-05-19T22:00:24+00:00

I have a txt file that I read with: fdata =[] with open(fn,’rb’) as

  • 0

I have a txt file that I read with:

fdata =[]
with open(fn,'rb') as fo:
     for i in xrange(1):
           fo.next()
     for line in fo:                       
           data = line.split(',')
           data = data[:23]
           fdata.append(data)    
     print fdata 

I would like convert the entire table to numbers from string. AND limit the table size to read to XXX lines.

  • 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-19T22:00:24+00:00Added an answer on May 19, 2026 at 10:00 pm

    To limit lines, try iterating using a counter and readlines():

    maxlines = 100
    lines = f.readlines()
    
    if maxlines > len(lines):  maxlines = len(lines)
    
    for i in xrange(maxlines):
      line = lines[i]
    
      # Do your stuff...
    

    To convert a string to a number (an integer in this case. float() is for floating points):

    print '9000' == 9000 # False.
    print int('9000') == 9000 # True
    

    So to make your table only include integers, convert each line (after splitting) into an integer. int() only returns an integer, so it doesn’t modify your variable. Replacing fdata.append(data)) with fdata.append(int(data() should do the trick.


    Okay, to convert your entire list into integers, just iterate over each of those 23 elements to convert them into integers. This works for an arbitrary list of strings:

    for element in data:
      element = int(element)
    

    To convert your list into integers, but to exclude your first element, loop through it:

    for i in xrange(1, len(data)): # I used 1 because 0 is the first element. This skips it.
      data[i] = int(data[i])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that read the next line in a txt file and
I have developed J2ME application that read data from product.txt file located in binary
I have the following code that read input from txt file as follow Paris,Juli,5,3,6
So I currently have this code to read an accounts.txt file that looks like
Say I have this simple python script: file = open('C:\\some_text.txt') print file.readlines() print file.readlines()
I have some data in a .txt file that I dragged over to resources
I have a txt file that is generated on the server and contains newlines.
I have a .txt file that contains a list of names and some numbers.
I have a txt file that created in notepad , containing these lines for
I have a txt file that include information as follow: Jack Jim Bill's Father

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.