[Tutor] fixed or variable length fields?

Paul Tremblay phthenry@earthlink.net
Sat Mar 1 04:28:01 2003


Would I gain a speed increase by using fixed fields rather than variable
length ones?

I am writing a script that converts Microsoft RTF to XML. The first
stage breaks the file into tokens and puts one token on a line:


ob<nu<nu<nu<0001<{
cw<nu<nu<nu<rtf>true<rtf
cw<nu<nu<nu<macintosh>true<macintosh
cw<nu<nu<nu<font-table>true<font-table

(Fields delimited with "<" and ">" because all "<" and ">" have
been converted to "&lt;" and "&gt;"

I will make several passes through this file to convert the data.

Each time I read a line, I will use the string method, and sometimes the
split method:

if line[12:23] == 'font-table':
	info = [12:23]
	list = info.split(">")
	if list[1] == 'true':
		# do something

If I use fixed length fields, then I won't have to do any splitting. I
also know that in perl, there is a way to use 'pack' and 'unpack' to
quickly access fixed fields. I have never used this, and don't know if
the pack in Python is similar.

If fix fields did give me a speed increase, I would certainly suffer
from readibility. For example, the above 4 lines of tokens might look
like:

opbr:null:null:null:0001
ctrw:null:null:true:rtfx
ctrw:null:null:true:mact
ctrw:null:null:true:fntb

Instead of 'macintosh', I have 'mact'; instead of 'font-table', I have
'fntb'. 

Thanks

Paul

-- 

************************
*Paul Tremblay         *
*phthenry@earthlink.net*
************************