0

How can I see class methods via the command line for Python definitions?

In java, if I want to see the all methods of the Scanner class, then I can do it by this way:

javap *full_class_name*

Example:

 user@hostname:~$ javap java.util.Scanner
    Compiled from "Scanner.java"
    public final class java.util.Scanner implements java.util.Iterator<java.lang.String>, java.io.Closeable {
      static final boolean $assertionsDisabled;
      public java.util.Scanner(java.lang.Readable);
      // etc. ...
    }

I want to see all the methods of a class in python, how can I do it? I want to be able to look up what methods are available when coding; I'm a beginner and don't want to have to search the internet each time.

2
  • @SanjayPrajapat: the reason people ask is because if you needed those names programmatically then my answer would have been different. Commented Oct 7, 2017 at 21:21
  • (When you have a practicable method to get information programmatically, it should be obvious how to roll your own command line tool. Most IDEs support accessing what API doc is available, if in the context of auto completion. Make providing such information for code you write a habit.) Commented Oct 8, 2017 at 6:54

1 Answer 1

2

You can use the pydoc library to get help on Python objects, including the methods:

$ python -m pydoc str
Help on class str in module builtins:

class str(object)
 |  str(object='') -> str
 |  str(bytes_or_buffer[, encoding[, errors]]) -> str
 |
 |  Create a new string object from the given object. If encoding or
 |  errors is specified, then the object must expose a data buffer
 |  that will be decoded using the given encoding and error handler.
 |  Otherwise, returns the result of object.__str__() (if defined)
 |  or repr(object).
 |  encoding defaults to sys.getdefaultencoding().
 |  errors defaults to 'strict'.
 |
 |  Methods defined here:
 |
 |  __add__(self, value, /)
 |      Return self+value.
 |
 |  __contains__(self, key, /)
 |      Return key in self.
# .... etc.

If you already have a Python interpreter open, you can use the built-in help() function to access the same information.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you , i don't know why everyone is downvoting this question ?
@SanjayPrajapat: I can't read minds, sorry. I suggest you read How to Ask carefully, follow the advice given and in future share your research in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.