Attributes (+Numerical Python)

William Park parkw at better.net
Fri Apr 14 15:49:49 EDT 2000


On Fri, Apr 14, 2000 at 03:15:58PM -0400, Matthew Hirsch wrote:
> Hi All,
> 
> In Numerical Python, you can say something like vector.imag and it will 
> return arrays of the imaginary parts of the elements in the array, 
> vector.  But this attribute only exists when the array is complex.  I'd 
> like to do something like the following, but I have no idea what the 
> syntax should be:
> 
> if the .imag attribute exists:
>    do something
> else
>    do something else
> 
> How should this be written?
> 
> Thanks for your help,
> Matt

How about
    try:
	<do something with 'vector.imag'>
    except:	    # or except AttributeError:
	<do something else>

--William




More information about the Python-list mailing list