title: reading struct in python from created struct in c
body: <p>I am very new at using Python and very rusty with C, so I apologize in advance for how dumb and/or lost I sound.</p>
  
  <p>I have function in C that creates a .dat file containing data. I am opening the file using Python to read the file. One of the things I need to read are a struct that was created in the C function and printed in binary. In my Python code I am at the appropriate line of the file to read in the struct. I have tried both unpacking the stuct item by item and as a whole without success. Most of the items in the struct were declared 'real' in the C code. I am working on this code with someone else and the main source code is his and has declared the variables as 'real'. I need to put this in a loop because I want to read all of the files in the directory that end in '.dat'. To start the loop I have:</p>
  
  <pre><code>for files in os.listdir(path):
    if files.endswith(".dat"):
      part = open(path + files, "rb")
      for line in part:
  </code></pre>
  
  <p>Which then I read all of the lines previous to the one containing the struct. Then I get to that line and have:</p>
  
  <pre><code>      part_struct = part.readline()
        r = struct.unpack('&lt;d8', part_struct[0])
  </code></pre>
  
  <p>I'm trying to just read the first thing stored in the struct. I saw an example of this somewhere on here. And when I try this I'm getting an error that reads:</p>
  
  <pre><code>struct.error: repeat count given without format specifier
  </code></pre>
  
  <p>I will take any and all tips someone can give me. I have been stuck on this for a few days and have tried many different things. To be honest, I think I don't understand the struct module but I've read as much as I could on it.</p>
  
  <p>Thanks!</p>