Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Error With Reading Files In Directory And Calculating Values
I'm trying to run the following code which carries out some calculations on files I have data for with functions for CentreOfMass and SED.
directory = ["./nrl169","./nrl177"]    

frame = list()
J = 1
sed = list()

for dir in directory:
    for filename in os.listdir(dir):
        pathname = os.path.join("directory", filename)
        if filename.endswith(".dump"):
            f = open(pathname, 'r')
            text =
            for line in f:
                if J>1:
                    frame = np.array(frame)
                    COM = CentreOfMass(frame, N)
                    frame = list()
                J = J + 1


However, when I run this I get the following error:

Traceback (most recent call last):
File "", line 79, in <module>
f = open(filename, 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'equil_T9.dump'
To explain clearly what I want to do - I am looking to calculated the SED function I have for each of the files I have contained the the two directories listed above. I then want to plot a histogram of these values. Can anyone help me with the error i'm getting and tell me if i'm on the right track?
you probably mean pathname = os.path.join(dir, filename)
(Feb-15-2020, 01:54 PM)Gribouillis Wrote: you probably mean pathname = os.path.join(dir, filename)
Thank you I just realised this but now have a second error regarding an array.

it reads Traceback (most recent call last):
File "", line 86, in <module>
COM = CentreOfMass(frame, N)
File "", line 17, in CentreOfMass
IndexError: too many indices for array

relating to a section of code as follows:

def CentreOfMass(frame, N):
include_types = np.nonzero(init==41)
frame = frame[:refor_types, :]
limit_frame = frame[(frame[:,-1]<41),:]
mol = len(set(limit_frame[:,-3]))

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python 2.7 Import error. Directory and filename conflict petcoo00 2 106 Feb-02-2020, 08:46 PM
Last Post: snippsat
  error merge text files ledgreve 3 177 Nov-18-2019, 12:41 PM
Last Post: DeaD_EyE
  Error: too many values to unpack Mike 1 1,005 Oct-30-2019, 03:07 PM
Last Post: buran
  EOFError: EOF when reading a line - Runtime Error RavCOder 6 1,477 Sep-27-2019, 12:22 PM
Last Post: RavCOder
  Project, Reading Data from a spreadsheet. Error message!! Shafla 1 268 Sep-27-2019, 10:44 AM
Last Post: buran
  How do I read the HTML files in a directory and write the content into a CSV file? glittergirl 1 265 Sep-23-2019, 11:01 AM
Last Post: Larz60+
  Reading DBF files from Amazon s3 throwing error - 'int' object has no attribute 'isa abeesm 1 297 Sep-22-2019, 05:49 PM
Last Post: ndc85430
  How do I turn a directory of HTML files into one CSV? glittergirl 2 269 Sep-21-2019, 05:33 PM
Last Post: glittergirl
  unable to list files in a directory christober 2 196 Sep-18-2019, 11:45 PM
Last Post: wavic
  How can I compare Python XML-Files and add missing values from one to another kirat 2 236 Aug-30-2019, 12:17 PM
Last Post: perfringo

Forum Jump:

Users browsing this thread: 1 Guest(s)