prasad rao wrote:

Hello
It is printing wether the item is callable or not.
I want it to print
sys.getdefaultencoding
ASCII
sys.getfilesystemencoding
mbcs

Like that

Prasad

But when you get to sys.exit(), you'll be terminating your test. In general, it's not safe to just run through a list of functions, calling them all with default arguments. You never know what side effects may occur.

Others that'll fail include sys.getrefcount(), sys.getsizeof(), sys.setcheckinterval(). They have at least one required parameter, as do many more of the setXXXX functions.

So, ignoring callable functions (which shouldn't be called unless you've read the docs), try the following:

import sys
for attrib in dir(sys):
   if callable(sys.__getattribute__(attrib)):
       print 'Callable: sys.%s' % attrib
   else:
       print 'Not Callable: sys.%s = %s' % (attrib, getattr(sys, attrib))

Note that sometimes the output is multiline, and quite long - see sys.__doc__ for example.



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to