Usage of dir() and help() functions for all available features of methods/objects

I’m taking Data Analysis with Python course and am trying to rely mostly on offline documentation so far. I used zeal (apt install zeal for Linux) - an offline documentation
browser, but its search seems awful and some GUI rendering for Pandas docs as well.

I’m using dir() and help() methods in Jupyter Notebook to get more info on function definitions used in the course,:

help(plt.plot)
dir(opened_csvfile_handle)
dir(opened_csvfile_handle.loc)
help(opened_csvfile_handle.apply)
help(opened_csvfile_handle.head)

And I can’t find for example which values for plot types does the argument “kind” of plot()
function takes. There seems to be no such info in the output of help(plt.plot).

dir() shows all names defined in a namespace or for a given object/function. For methods it returns many types like name and _name. As I know, a single underscore in _name is only a convention to denote private methods inside classes. And double underscored names are also some methods used only within a class definition. Does double underscore have any functional value (like keywords, for example)? Can I use double underscored methods available for a method/object queried via dir()?

The single underscore prefix in Python is a convention indicating a name is meant for internal use. It is considered “protected” but not “private” in the context of object-oriented terminology. In practice, it doesn’t prevent you from accessing the variable or method, but the leading underscore suggests that it’s internal to the module/class and shouldn’t be accessed directly from outside. In other coding languages there are actual keywords that dictate the scope of variables, such as ‘private’ or ‘protected’ in java, but in this case we’re talking about convention to help you keep your code organized.

When a name is prefixed with double underscores, Python will name-mangle the attribute name. This is intended to give a stronger indication that the variable or method should not be accessed from outside the class/module.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.