struct - Library Reference 4.3

Colin J. Williams cjw at sympatico.ca
Mon Mar 25 08:03:16 EST 2002


Martin,

Thanks, I did not spot this.

I was looking for some clue as to which argument is causing
the exception.  As an example:

import exceptions, sys
try:
  print `struct.pack('iii', 22, 22.6, '23.6')`
except struct.error:
  print 'z1:', struct.error().args
  print 'z2:', sys.exc_info()[1]
  print 'z3:', sys.exc_info()[1].__getitem__(0)

Neither 22.6 or '23.6' is an integer, but it seems that '23.6'
is the source of the problem.

Various things I've tried don't identify the specific value.

Colin W.

"Martin v. Loewis" wrote:

> "Colin J. Williams" <cjw at sympatico.ca> writes:
>
> > This gives no indication as to which of the argument's
> > components is the source of the grief.
> >
> > Any information about the error function would be
> > appreciated.
>
> It's not a function - it is an exception. If you want to catch the
> exception, you need to write a try-except-block.
>
> The exception does not provide any further information beyond the
> string that is printed - it is assumed that the nature of the error
> would be obvious once you read the string.
>
> Regards,
> Martin






More information about the Python-list mailing list