hkhr hkhr - 2 months ago 11
Python Question

print list in proper way python

I have a list "values" it has the types information i just to print it properly

in ipython notebook i am trying to print

case1:

> print values
[<type 'str'>, <type 'str'>, <type 'str'>, <type 'str'> <type 'int'>]


case2:but if i simply do

>values
[str, str, str, str, int]


Ultimately i just case2 way of printing and tried to do it many ways but not getting it.

Answer

You have a list of type objects, and both __str__ and __repr__ of type objects have a <type 'x'> form.

If you want to print list of names of type objects you need to perform conversion manually:

print [t.__name__ for t in values]
Comments