On Jul 9, 5:04 pm, dp_pearce <[EMAIL PROTECTED]> wrote: > count = 0 > dmntString = "" > for z in range(0, Z): > for y in range(0, Y): > for x in range(0, X): > fraction = domainVa[count] > dmntString += " " > dmntString += fraction > count = count + 1 > dmntString += "\n" > dmntString += "\n" > dmntString += "\n***\n > > dmntFile = open(dmntFilename, 'wt') > dmntFile.write(dmntString) > dmntFile.close() > Can anyone see a way of speeding this loop up?
I'd consider writing it like this: def dmntGenerator(): count = 0 for z in xrange(Z): for y in xrange(Y): for x in xrange(X): yield ' ' yield domainVa[count] count += 1 yield '\n' yield '\n' yield '\n***\n' You can make the string using ''.join: dmntString = ''.join(dmntGenerator()) But if you don't need the string, just write straight to the file: for part in dmntGenerator(): dmntFile.write(part) This is likely to be a lot faster as no large string is produced. -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list