“自动完成和智能感知”由 Python 服务器提供。在vscode中,基本上你可以选择'Jedi'或'Microsoft',它们的动作不同。老实说,两者都不够好,如果你利用Pycharm,你不会遇到这个问题。
在《绝地武士》中:
'import pygame', 'import pygame.display', 'from pygame import *': display 将被视为一个值,因此它们不起作用。
'from pygame import display', 'from pygame import display as display': display 将被视为变量,因此它们不起作用。
'import pygame.display as display': display 会被当作一个模块,所以它可以工作。
'import pygame', 'import pygame.camera', 'import pygame.camera as camera', 'from pygame import camera', 'from pygame import camera as camera':相机将被视为一个模块,所以它可以工作。
'from pygame import *':它不起作用,因为找不到模块'pygame'或'camera'。
为什么会这样?这是因为 'display' 模块是通过 'display.cp38-win32.pyd' 文件提供的,它是一个 .pyd 文件。而“相机”是通过“camera.py”文件提供的,它是一个python文件。
在“微软”中:
'import pygame': display 将被视为一个值,所以它不起作用。
'import pygame.display', 'import pygame.display as display', 'from pygame import display', 'from pygame import display as display', 'from pygame import *': display 将被视为一个模块,所以他们工作。
'import pygame', 'from pygame import *': 找不到相机模块,所以它们不起作用。
'import pygame.camera', 'import pygame.camera as camera', 'from pygame import camera', 'from pygame import camera as camera':可以找到相机模块,所以它们可以工作。
为什么会这样?您可以参考 https://docs.python.org/zh-cn/3/tutorial/modules.html#importing-from-a-package 了解为什么 'from pygame import *' 在显示器和相机之间的工作差异。