Anyone has a nice "view_var" procedure ?

Adam adamgarstang at googlemail.com
Tue Jan 16 00:47:45 CET 2007


Stef Mientki wrote:

> hello,
>
> Is there some handy/ nice manner to view the properties of some variable ?
> As a newbie, I often want to see want all the properties of a var,
> and also some corner values (large arrays) etc.
>
> Probably it's not so difficult,
> but I don't see how to distinguish for example between a string and an
> array. An array has a shape, a string not etc.
>
>
> thanks,
> Stef Mientki

I am also a newbie so if this is not what you want I can't give much
more as of yet.

You can use type() to check what a Variable is. Usage:
#-------------Python Code-----------------------------
>>> aVar = ["zero", 1, float(2)]
>>> type(aVar)
<type 'list'>
>>> type(aVar[0])
<type 'str'>
>>> type(aVar[1])
<type 'int'>
>>> type(aVar[2])
<type 'float'>
>>> if type(aVar[1]) == int:
	print "test"

test
#-----------------End Code-------------------------------


There are also  function like len(). Usage:
#-------------Python Code-----------------------------
>>> len(aVar)
3
>>> len(aVar[0])
4
#-----------------End Code-------------------------------

Hope this helps.
Adam




More information about the Python-list mailing list