How to enable autocomplete (IntelliSense) for python package modules?

2024/10/7 2:20:48

This question is not about Pygame, I'm usin Pygame as an example.

While experimenting with Pygame I've noticed that autocomplete is not working for some modules. For example, if I start typing pygame.mixer autocomplete shows MissingModule. While searching for a solution I've found a lot of similar questions for various text editors and modules that have parts written in C. I am using Visual Studio Code, python path is set correctly and my code runs fine. One strange workaround is modifying Pygame's __init__.pyenter image description here What's the right way to enable autocomplete?

Answer

I've found a solution, but I would appreciate some explanation from someone more experienced with Python:

import package.module as module

With Pygame mixer it's:

import pygame.mixer as mixer 

enter image description here

But I still don't understand why autocomplete for import.package.module doesn't work, but import.package.module as module does.

https://en.xdnf.cn/q/70293.html

Related Q&A

Integrating a redirection-included method of payment in django-oscar

I am developing a shopping website using django-oscar framework, in fact I am using their sandbox site. I want to add payment to the checkout process, but the thing is, I am totally confused!Ive read t…

How can I unpack sequence?

Why cant I do this:d = [x for x in range(7)] a, b, c, d, e, f, g = *dWhere is it possible to unpack? Only between parentheses of a function?

Can I statically link Cython modules into an executable which embeds python?

I currently have an executable compiled from C++ that embeds python. The embedded executable runs a python script which load several Cython modules. Both the Cython modules and the executable are lin…

How to Store Graphs?

Lets say i have a class Graph defined.graph iowa = {.....nodes:{edges.......}}and similar graph clusters.once the script is running its all in the object. But how do you store the Graph info (including…

regex for only numbers in string?

I cant find the regex for strings containing only whitespaces or integers. The string is an input from user on keyboard. It can contain everything but \n (but it doesnt matter I guess), but we can focu…

How to build a chi-square distribution table

I would like to generate a chi-square distribution table in python as a function of the probability level and degree of freedom.How to calculate the probability, given a known chi-value and degree of f…

Reset all weights of Keras model

I would like to be able to reset the weights of my entire Keras model so that I do not have to compile it again. Compiling the model is currently the main bottleneck of my code. Here is an example of w…

How to fix NaN or infinity issue for sparse matrix in python?

Im totally new to python. Ive used some code found online and I tried to work on it. So Im creating a text-document-matrix and I want to add some extra features before training a logistic regression mo…

Mutable default argument for a Python namedtuple

I came across a neat way of having namedtuples use default arguments from here.from collections import namedtuple Node = namedtuple(Node, val left right) Node.__new__.__defaults__ = (None, None, None) …

Windows notification with button using python

I need to make a program that alerts me with a windows notification, and I found out that this can be simply done with the following code. I dont care what library I use from win10toast import ToastNo…