Skip to content Skip to sidebar Skip to footer

Why Does The Python Help Class Interpret Sub-classes Of The Str Class As Module Names?

When the python help function is invoked with an argument of string type, it is interpreted by pydoc.Helper.help as a request for information on the topic, symbol, keyword or modul

Solution 1:

The simple answer is that making user-defined subclasses of str is not the most common case—partly because the user-defined data but not the string data would be mutable. By the time you have to deal with such, it’s imagined that you know how to write help(type(x)), and using isinstance rather than type(…) is … is the correct default in general. (The other way, you’d have to use help(str(x)) if you wanted to use it, like any other string, to select a help topic, but that’s surely even rarer.)


Post a Comment for "Why Does The Python Help Class Interpret Sub-classes Of The Str Class As Module Names?"