There is more than one way, but you could use a for() loop with step=4. We don't have the file so you will have to test and correct this yourself.[code]def block_generator():
with open ('test', 'r') as lines:
data = lines.readlines ()[5::]
for ctr in range(0, len(data), 4):
block =  … Read More
Here is a pure "itertool style" solution
from itertools import islice, repeat, takewhile
def blocks(fileobj, size=4):
blank = " " * 10
lines = (line for line in fileobj if not line.startswith(blank))
return takewhile(len, (list(islice(lines, 0, size)) for x in repeat(None)))
with open("blocks.txt") as ifh:
for b in blocks(ifh): … Read More
An other way,nice use of itertools Gribouillis.
[CODE]def blocks(filename, chunks):
with open(filename) as f:
numb_list = [i for i in f]
return [numb_list[i:i+chunks] for i in range(0, len(numb_list), chunks)]
filename = 'numb.txt'
chunks = 4
print blocks(filename, chunks)
[['56.71739\n', '56.67950\n', '56.65762\n', '56.63320\n'], ['56.61648\n', '56.60323\n', '56.63215\n', '56.74365\n'], ['56.98378\n', '57.34681\n', … Read More
As I said, your algorithm is wrong. There is no reason to call blocks_generator() for each output file. It only needs to be called once. Try this first
def tgrid_files ():
"""Creates the t.grid files"""
times = open ('test', 'r') # what is this ?
header = header_tgrid_files()
file_names … Read More
[QUOTE=eikonal;1684980]Oh man I can't believe it!!!! It's working!!!! I sweat blood over it!
One last thing if you can: why I'm getting this output in the file:
[' 54.22953\n', ' 54.17732\n', ' 54.13724\n', ' 54.10664\n', ' 54.08554\n'']
rather than, you know just a column without list and string symbols like: … Read More