Text after "
How can I check in Python whether an object is a module or not?
Here's what I tried:
& gt; & Gt; & Gt; Import systems and gt; & Gt; & Gt; Sys.modules ["sys"] .__ class__ & lt; Class 'module' & gt; & Gt; & Gt; & Gt; Isinstance (sys.modules ["sys"], module) Traceback (most recent call last): File module and gt; In & lt; line1, "& lt; stdin & gt;"; Name error: Name 'module' is not defined & gt; & Gt; & Gt; Sys.modules ["sys"] .__ Class __.__ Module__ 'Biltin' & gt; & Gt; & Gt; Import builds and gt; & Gt; & Gt; Biltins. Module traceback (most recent call final): File "& lt; stdin>", line 1, & lt; Module & gt; AttributeError: 'module' object has no attribute 'module' & gt ; & Gt; & Gt; Import System, Type & gt; & Gt; & Gt; Isinstance (sis, types.ModuleType) This is true type module also provides several other types: & Gt; & Gt; & Gt; dir (type) [ 'BooleanType', 'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'CodeType', 'complexType', 'DictProxyType', 'DictType', 'DictionaryType', 'EllipsisType', ' 'type', 'Flottaip' Fremtaip 'function type', 'Generator type', 'Getsat Dayskriptr type', 'Instastaip' Intteep 'Lmbada type', 'list type', 'Longtip' "Sdasidiskriptr type ',' Methdteep '' ModuleType 'NoneType' NotImplementedType 'ObjectType' SliceType 'StringType' StringTypes 'TracebackType' TupleType 'TypeType' Unbondmethodeepe 'Unikodaeteepe' Srngeteepe '__builtins__' __do__ '__fail__' __nam__ '__packej__'] & gt; & Gt; & Gt;
Comments
Post a Comment