checking 'type' programmatically

M

mk

Disclaimer: this is for exploring and debugging only. Really.

I can check type or __class__ in the interactive interpreter:

Python 2.6.2 (r262:71600, Jun 16 2009, 16:49:04)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> p=subprocess.Popen(['/bin/ls'],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
>>> p
>>> (so, se) = p.communicate()
>>> so 'abc.txt\nbak\nbox\nbuild\ndead.letter\nDesktop\nhrs\nmbox\nmmultbench\nmmultbench.c\npyinstaller\nscreenlog.0\nshutdown\ntaddm_import.log\nv2\nvm\nworkspace\n'
>>> se ''
>>> so.__class__
>>> type(so)
>>> type(se)
<type 'str'>

But when I do smth like this in code that is ran non-interactively (as
normal program):

req.write('stderr type %s<br>' % type(se))
req.write('stderr class %s<br>' % str(se.__class__))

then I get empty output. WTF?

How do I get the type or __class__ into some object that I can display?


Why do that: e.g. if documentation is incomplete, e.g. documentation on
Popen.communicate() says "communicate() returns a tuple (stdoutdata,
stderrdata)" but doesn't say what is the class of stdoutdata and
stderrdata (a file object to read? a string?).

Regards,
mk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top