what does type(subprocess.Popen)==<class 'type'> mean?

Steve D'Aprano steve+python at pearwood.info
Sat Oct 29 11:22:40 EDT 2016


On Sun, 30 Oct 2016 01:55 am, oyster wrote:

> why does not type(subprocess.Popen)==<class 'module'>? Thanks

Because Popen is not a module.

Why do you expect it to be a module?

py> type(int)
<class 'type'>
py> type(float)
<class 'type'>
py> type(str)
<class 'type'>
py> class X(object):
...     pass
...
py> type(X)
<class 'type'>



>>>> type(subprocess.Popen)
> <class 'type'>

Popen is a class, also known as a "type".


>>>> import os
>>>> type(os.path)
> <class 'module'>

os.path is a module, just like os.

Inside the os module, you will find code that looks something like this:


if the operating system is Windows:
    import ntpath as path
elif the operating system is Unix:
    import posixpath as path
else:
    import genericpath as path


So os.path is a module.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list