小编Zac*_*ner的帖子

如何使用大小写匹配来检查Python中的变量类型?

我有这段代码来检查变量在乘法时是否是Vector2我的Vector2类中的数字或 a 。

def __mul__(self, other):
    match type(other):
        case int | float:
            pass
        case Vector2:
            pass
Run Code Online (Sandbox Code Playgroud)

如果我运行这个,我会得到SyntaxError: name capture 'int' makes remaining patterns unreachable,当我将鼠标悬停在 vscode 中时,它会给我:

"int" is not accessed
Irrefutable pattern allowed only as the last subpattern in an "or" pattern
All subpatterns within an "or" pattern must target the same names
Missing names: "float"
Irrefutable pattern is allowed only for the last case statement
Run Code Online (Sandbox Code Playgroud)

如果我删除 | float它仍然不起作用,所以我不能将它们分开。

types pattern-matching python-3.10

11
推荐指数
1
解决办法
8887
查看次数

如何使用 pygame 进行绘图,同时使用 pyopengl 进行绘图?

我有一个用 python 编写的程序,并使用 pygame 和 pyopengl。唯一的问题是,我无法使用 pygame.draw 在屏幕上绘制任何内容,而这正是我将用于与程序交互的东西。我想知道是否有一种方法可以使用 pygame 的系统进行绘图,同时也可以在其后面使用 pyopengl 进行 3D 绘图。

python opengl pygame pyopengl

5
推荐指数
1
解决办法
953
查看次数