Working with Huge Text Files

cwazir at cwazir at
Sun Mar 20 03:12:35 CET 2005

Lorn Davies wrote:

> if  (fields[8] == 'N' or 'P') and (fields[6] == '0' or '1'):
> ## This line above doesn't work, can't figure out how to struct?

In Python you would need to phrase that as follows:
  if  (fields[8] == 'N' or fields[8] == 'P') and (fields[6] == '0'
  or fields[6] == '1'):
or alternatively:
  if  (fields[8] in ['N', 'P']) and (fields[6] in ['0', '1']):

> The main changes were to create a check for the length of fields[3],
> I wanted to normalize it at 6 digits...

Well, you needn't really check the length - you could directly do this:
fields[3] = (fields[3].replace('.', '') + '000000')[:6]
(of course if there are more than 6 digits originally, they'd get
truncated in this case)

Chirag Wazir

More information about the Python-list mailing list