Anyone has a nice "view_var" procedure ?

Gabriel Genellina gagsl-py at
Tue Jan 16 00:33:54 CET 2007

At Monday 15/1/2007 17:45, Stef Mientki wrote:

>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.

You can try dir(x), vars(x). If you want a "nice print", see the pprint module.

py> import csv
py> x = csv.DictReader('') # a bogus object
py> x
<csv.DictReader instance at 0x00BC79B8>
py> dir(x)
['__doc__', '__init__', '__iter__', '__module__', 'fieldnames', 
'next', 'reader'
, 'restkey', 'restval']
py> vars(x)
{'restkey': None, 'restval': None, 'fieldnames': None, 'reader': 
<_csv.reader ob
ject at 0x00BC98B8>}
py> from pprint import pprint
py> pprint(vars(x))
{'fieldnames': None,
  'reader': <_csv.reader object at 0x00BC98B8>,
  'restkey': None,
  'restval': None}

>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.

Yes, strings share a lot of functionality with other sequence types: 
[], len, in, etc. You can test if an object is a string using 
isinstance(obj, str). If you want to include unicode objects too, use 
isinstance(obj, basestring).

Gabriel Genellina
Softlab SRL 


Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 

More information about the Python-list mailing list