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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:36:21+00:00 2026-06-01T12:36:21+00:00

I have example: for line in IN.readlines(): line = line.rstrip(‘\n’) mas = line.split(‘\t’) row

  • 0

I have example:

    for line in IN.readlines():
        line = line.rstrip('\n')
        mas = line.split('\t')
        row = ( int(mas[0]), int(mas[1]), mas[2], mas[3], mas[4] )
        self.inetnums.append(row)
    IN.close()

If ffilesize == 120mb, script time = 10 sec. Can I decrease this time ?

  • 1 1 Answer
  • 3 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-01T12:36:22+00:00Added an answer on June 1, 2026 at 12:36 pm

    You may gain some speed if you use a List Comprehension

    inetnums=[(int(x) for x in line.rstrip('\n').split('\t')) for line in fin]
    

    Here is the profile information with two different versions

    >>> def foo2():
        fin.seek(0)
        inetnums=[]
        for line in fin:
            line = line.rstrip('\n')
            mas = line.split('\t')
            row = ( int(mas[0]), int(mas[1]), mas[2], mas[3])
            inetnums.append(row)
    
    
    >>> def foo1():
        fin.seek(0)
        inetnums=[[int(x) for x in line.rstrip('\n').split('\t')] for line in fin]
    
    >>> cProfile.run("foo1()")
             444 function calls in 0.004 CPU seconds
    
       Ordered by: standard name
    
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            1    0.003    0.003    0.004    0.004 <pyshell#362>:1(foo1)
            1    0.000    0.000    0.004    0.004 <string>:1(<module>)
            1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
          220    0.000    0.000    0.000    0.000 {method 'rstrip' of 'str' objects}
            1    0.000    0.000    0.000    0.000 {method 'seek' of 'file' objects}
          220    0.000    0.000    0.000    0.000 {method 'split' of 'str' objects}
    
    
    >>> cProfile.run("foo2()")
             664 function calls in 0.006 CPU seconds
    
       Ordered by: standard name
    
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            1    0.005    0.005    0.006    0.006 <pyshell#360>:1(foo2)
            1    0.000    0.000    0.006    0.006 <string>:1(<module>)
          220    0.000    0.000    0.000    0.000 {method 'append' of 'list' objects}
            1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
          220    0.001    0.000    0.001    0.000 {method 'rstrip' of 'str' objects}
            1    0.000    0.000    0.000    0.000 {method 'seek' of 'file' objects}
          220    0.001    0.000    0.001    0.000 {method 'split' of 'str' objects}
    
    
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example we have this line chart at Google Code API there is a
OK. For example I have this line in my txt file: 1|1,12;7,19;6,4;8,19;2,2 As you
I have a bash script mystuff containing a line like lynx -dump http://example.com >tmpfile
Given I have a long phrase, say, in line :12 , as this example:
I write this code: f = open('example.txt','r') lines = f.readlines() for i, line in
I have example.org and foo.example.org pointing to the same directory, /var/www/html/ , and want
Anyone have example Rx code that shows how to execute an action due to
If I have example.com/dir and dir is basically a folder in the example.com server,
The issue Let's say that I have example.com, example.org and example.net. All of these
I have this example FactoryGirl.define do @site = FactoryGirl.create(:my_site) factory :user do email {

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.