2

While coding in pygame, I realised that VSCode was not showing up itellisense for quite some pygame modules, and instead showed those modules as variables. After some digging, I found out that if you do import pygame.display as display, the intellisense show up just fine. Is there any way in which I can use intelliense without importing these modules like this?

Vthechamp
  • 636
  • 1
  • 8
  • 20
  • Please share the code that shows how you are importing pygame. And you can do `from pygame import display` for the same result as the example you say works. – Brett Cannon Jun 22 '20 at 20:56

1 Answers1

1

'Autocomplete and IntelliSense' was provided by Python Server. In vscode, basically you can choose 'Jedi' or 'Microsoft', and they are with different actions. Honestly, both of them are not well enough, if you take advantage of Pycharm, you will not come across this problem.

In 'Jedi':


'import pygame', 'import pygame.display', 'from pygame import *': display will be treated as a value, so they don't work.

'from pygame import display', 'from pygame import display as display': display will be treated as a variable, so they don't work.

'import pygame.display as display': display will be treated as a module, so it works.


'import pygame', 'import pygame.camera', 'import pygame.camera as camera', 'from pygame import camera', 'from pygame import camera as camera': camera will be treated as a module, so it works.

'from pygame import *': it doesn't work, because can't find module 'pygame' or 'camera'.


Why did it happen? This is because the 'display' module was provided through 'display.cp38-win32.pyd' file, it is a .pyd file. And the 'camera' was provided through 'camera.py' file, it is a python file.

In 'Microsoft':


'import pygame': display will be treated as a value, so it doesn't work.

'import pygame.display', 'import pygame.display as display', 'from pygame import display', 'from pygame import display as display', 'from pygame import *': display will be treated as a module, so they works.


'import pygame', 'from pygame import *': can't find camera module, so they don't work. 'import pygame.camera', 'import pygame.camera as camera', 'from pygame import camera', 'from pygame import camera as camera': can find camera module, so they works.
Why did it happen? you can refer to https://docs.python.org/zh-cn/3/tutorial/modules.html#importing-from-a-package for why 'from pygame import *' work difference between display and camera.
Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13