I've highlighted the heading and footer in red. What I would like to do is have a code completely crop these sections. I have done some RE matching, but don't know what is the best way to identify the entire line as a string. Is there a simple, smart way to do this?

This should work. I have not actually tested that it even 'compiles', but you can see the pattern, right?

with open(theFileName,'r') as inbound:
with open(theNewFileName, 'w') as outbound:
state = 'skip'
for line in inbound:
if line.startswith('>>>>>Begin Processed Spectral Data'):
state = 'write'
continue
if line.startswith('>>>>>End Processed Spectral Data'):
state = 'skip'
continue
if 'write' == state:
outbound.write(line)

I suppose the continue in line 10 could better be break so then line 9 is unneeded.

I like this solution. However, I noticed if the file itself does not have a header, then this program won't recognize it. I've written your code here into a function called 'import data'. Since I have files that have headers and files that dont, I was thinking something like this:

try:
(if first line is composed of digits)
print lines
else:
call import data (the code you wrote)

What would be the best syntax for the try statement do you think? I was thinking of doing what the poster above said:

I like this solution. However, I noticed if the file itself does not have a header, then this program won't recognize it. I've written your code here into a function called 'import data'. Since I have files that have headers and files that dont, I was thinking something like this:

try:
(if first line is composed of digits)
print lines
else:
call import data (the code you wrote)

What would be the best syntax for the try statement do you think? I was thinking of doing what the poster above said:

if line[0].isdigit():

What do you think?

Here's how I implemented it:

def import_data(file):
'''Reads in list of files and stores data in an array'''
f=open(file, 'r')
line=f.readline()
if not re.match("#", line):
if not line[0].isdigit(): #If first line is a letter, cut the header out
#######Cut's out header above and below the defined statements; so not very modular
def not_is_begin(line):
return not line.startswith(">>>>>Begin Processed Spectral Data<<<<<") #CUTS THE HEADER
def not_is_end(line):
return not line.startswith(">>>>>End Processed Spectral Data<<<<<")
lines=itt.dropwhile(not_is_begin, open(file))
lines = itt.islice(lines, 1, None)
lines = itt.takewhile(not_is_end, lines)
for line in lines:
line=line.strip()
sline=line.split()
print sline
#######
if line[0].isdigit(): #If first line is a number, just go on and
for line in f:
line=line.strip()
sline=line.split()
print sline

Let me know if you guys see anymore improvements. As of now, it would fail if the header didn't have the key strings that >>>>Begin spectra data<<< etc... and would fail if the header itself began with a number.

Let me know if you guys see anymore improvements. As of now, it would fail if the header didn't have the key strings that >>>>Begin spectra data<<< etc... and would fail if the header itself began with a number.

This code is horrible. You're saying that the code would fail if the header is different or non existent, but in order to write the code, we must know the different possible formats of your files. So what are these possible formats ?

I don't understand the if not re.match("#", line) . Why is it here ? Also there must be only 1 call to open() in your function.

This code is horrible. You're saying that the code would fail if the header is different or non existent, but in order to write the code, we must know the different possible formats of your files. So what are these possible formats ?

I don't understand the if not re.match("#", line) . Why is it here ? Also there must be only 1 call to open() in your function.

Sometimes the files do not have headers, but have the same type of data. I wanted to incorporate this into the code you wrote, so that if the header isn't there, it still reads the data.

Any ideas?

The re.match(#) is in case I ever put comments at the beginning of my file, but is not necessary.

Input is what you gave to us, and copy of it without beginning and end part, a comment added.
Pretty is my pretty printer module posted in code snippets in DaniWeb. If you do not us it you can mange with pprint or simple for loop.

Input is what you gave to us, and copy of it without beginning and end part, a comment added.
Pretty is my pretty printer module posted in code snippets in DaniWeb. If you do not us it you can mange with pprint or simple for loop.