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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:04:09+00:00 2026-06-08T10:04:09+00:00

In python 2.7, I need to perform the same operations for a list of

  • 0

In python 2.7, I need to perform the same operations for a list of file list.

Example,
# each file is a file descriptor
for example, fileX = open(“someString”, “a”)

 fileList1 = [file1, file2, file3,file4,file5] 
 fileList2 = [file11, file21, file31,file41,file51] 
 allFilelist = [fileList1, fileList2]

When I try to read/write some strings on them I get:

 line = item.readline()
 IOError: [Errno 9] Bad file descriptor

 # each file in allFilList is a file list 
 allFilList = [ifcxRpsFileNameL, ircxRpsFileNameL, transXRpsFileNameL, ifcxFileNameL, 
 ircxFileNameL, transXFileNameL]
 for eachFileList in allFilList :
    for item in eachFileList :
            #print item.read 
            line = item.readline()
            #for line in :
            print "the line read from ", item, " is " , line
            ll= line.strip("\n").split()
            if len(ll) == 0 :
                print "the file " , item , " is empty \n"
                exit  
            elif len(ll) != TOTAL_ITR :
                print "the len of the file " , item , " is not " , TOTAL_ITR , "\n"
                exit
            else:
                item.write("\n")
                lt = [float(num) for num in ll]
                item.write(min(lt))
                item.write(" ") 
                item.write(sum(lt)/len(lt))
                item.write(" ")
                item.write(max(lt))
                item.write(" ")
                item.write("\n")
                item.close()
                break

In response to this comment:

print out item before you try to read from it and post the output

the output is: <open file 'ND_ifxc_2010_RPS.dat', mode 'a' at 0x2ba38d1e9558>

  • 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-08T10:04:12+00:00Added an answer on June 8, 2026 at 10:04 am

    The problem that you have comes from the fact that the files you have open are opened with mode 'a', and therefore, not for reading. As a result, attempting to read from a file not open for reading gives you an error.

    You are likely better off storing a list of filepaths, and doing this:

    1. open with 'r' mode
    2. read lines
    3. based on your conditions, close them, reopen in 'a' mode and write the required lines.

    Hope this helps

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

Sidebar

Related Questions

I need to perform http PUT operations from python Which libraries have been proven
I am newbie in Python and I need help: I have a file with
I need a python script to perform a GET request on 2 urls. I
I need to perform some calculations a large list of numbers. Do array.array or
I'm trying to perform an inline operation where I need to sort a list
I need to implement a very simple web-server-like app in Python which would perform
I need to edit a configuration file through python and i tried searching on
I have a simple task I need to perform in Python, which is to
I have a nine character string and need to perform operations on groups of
I need to perform simple mathematical calculations in Python 2.7 with sums, subtractions, divisions,

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.