Intellisense python

Asked

Viewed 56 times

0

I’m learning to program in Python and is recurring in the following situation (this occurs in FDI pycharm, Atom and Spyder):

I imported the matplotlib as follows:

import matplotlib.pyplot as plt

When I type: plt. opens a window containing all the methods I can invoke. Then I select plt.axes(). Type plt.axes() no window is displayed with the methods I can call.

In the book I’m using it executes the command:

plt.axes().get_xaxis().set_visible(False)

I don’t understand why there is no window displaying the methods as shown above.

How to resolve such a situation?

  • You know which version of python the book is using ?

  • 3

    This is not only in Python, Ides in general do not give suggestions to return a function, basically because a lot can happen in a function and return numerous values or none. Chrome Devtools did not give feedback suggestions, but recently this has changed, now when you write on the JS console, for example, document.body.getElementById('el') and existing this element already has suggestions such as innerHTML, value, etc.

  • I removed my answer as I misinterpreted the question.

  • It uses python version 3. So from what I understand it’s normal for the IDE to behave like this?

1 answer

1

Python is a dynamic language, so it is not possible to know beforehand which methods can be invoked on an object without executing the code. What most Ides do is a static analysis of objects, returning methods associated with their "inferred type", but in the case of dynamic responses of functions, dynamic attributes and classes with __getattr__ defined this is very difficult or impossible to do without executing the code. It may even return invalid results.

The solution is to ignore what the editor is completing and write the code in the race - Use the IDE’s code completion feature to help you write long names, but don’t rely on it to list the available methods; For this use the documentation.

To illustrate this is an example of dynamic code: A class is defined with a method called metodo_nao_existe but soon after this method is removed from the class. Your IDE will probably get confused:

class Teste:
    def metodo_nao_existe(self):
        print("Eu nao existo")

def _metodo(self):
    print("Eu existo")

del Teste.metodo_nao_existe
Teste.metodo_existe = _metodo

t = Teste()
t.metodo_existe()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.