小编Ryd*_*dex的帖子

Pip 命令行“ImportError: No Module Named Typing”

运行命令给我以下错误:

C:\Python34\Scripts> pip install pygame

错误堆栈:

Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named 'typing'
Run Code Online (Sandbox Code Playgroud)

python pip

13
推荐指数
5
解决办法
7万
查看次数

如何在C中使用一个变量两次?

我对 C 很陌生,我试图在一行中使用一个变量两次:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int myAge = 10;
    char PL = "C";
    printf("I am Rydex (not my real name) and i am %d years old. This was made using %s", myAge, PL);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,我得到:

我是 Rydex(化名),今年 10 岁。这是使用 (null) 制作的

我得到的是“(null)”,而不是变量“PL”中的值。有人可以帮帮我吗?

c

2
推荐指数
1
解决办法
307
查看次数

Python:“|”的用途是什么

所以基本上,当我转到文件时builtins.py,我发现很多这样的函数:

def foo(o: object, arg: int | None = ...) -> int: ...
Run Code Online (Sandbox Code Playgroud)

当我自己尝试时,它实际上没有给出任何错误,并且仍然像正常功能一样工作。我想知道为什么人们使用它以及它的目的是什么。当我创建一个像该函数这样的函数时foo(这是之前给出的第一个示例):

def bar(arg: int, arg1: int | None = ...) -> int:
    try:
        return arg + arg1
    except:
        print('You cannot add a string and int together')
Run Code Online (Sandbox Code Playgroud)

我没有发现def bar(arg: int, arg1: int): ...和之间有什么区别def bar(arg: int, arg1: int | None = ...) -> int: ...

python

2
推荐指数
1
解决办法
103
查看次数

Tkinter:类型错误:+ 不支持的操作数类型:'int' 和 'str'

我试图在 python 中使用 tkinter 创建一个库:

import tkinter as tk

class Screen():
    def make_window(self, width: int=None, height: int=None, title: str=None) -> int:
        self.width = width
        self.height = height
        self.title = title
        new_window = tk.Tk()
        if width or height is not None:
            new_window.geometry(width + "x" + height)

win = Screen()
win.make_window()
Run Code Online (Sandbox Code Playgroud)

它工作正常,我得到了这个漂亮的小窗口: 在此处输入图片说明

但如果我这样做:

import tkinter as tk

class Screen():
    def make_window(self, width: int=None, height: int=None, title: str=None) -> int:
        self.width = width
        self.height = height
        self.title = title
        global new_window
        new_window = …
Run Code Online (Sandbox Code Playgroud)

python tkinter

0
推荐指数
1
解决办法
101
查看次数

标签 统计

python ×3

c ×1

pip ×1

tkinter ×1