RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-348667

rew's questions

Martin Hope
rew
Asked: 2024-06-19 02:36:45 +0000 UTC

java 中的 case success(var value) 语法

  • 9

我在代码中遇到了这样的构造

Integer a = switch (result) {
    case Success(var value) -> value;
    case Failure(Throwable e) -> Assertions.fail();
};

我不明白为什么你要把它推到构造函数中var value

case Success(var value)

我试着用谷歌搜索一下switch,但没有看到任何类似的东西。

请告诉我这个设计叫什么,或者发表一篇关于它的文章。

java
  • 1 个回答
  • 48 Views
Martin Hope
rew
Asked: 2024-02-25 21:48:38 +0000 UTC

连接到 docker 中引发的 postgres

  • 5

docker-compose.yml:

version: "3.9"
services:
  postgres:
    image: postgres:15
    environment:
      POSTGRES_DB: "db"
      POSTGRES_USER: "user"
      POSTGRES_PASSWORD: "password"
    ports:
      - "5432:5432"

让我们运行:

docker-compose up

我认为在完成操作后,我将能够postgress使用localhost. (我所说的连接,是指不进入docker容器的情况下进行连接)但是,这种方法不行;连接的时候会报错

connection to server at "localhost" (::1), port 5432 failed: FATAL:  role "user" does not exist

经过谷歌搜索,我找到了正确的连接方式 - 你不需要使用localhost,而是需要使用通过命令获取的地址

ifconfig -u | grep 'inet ' | grep -v 127.0.0.1 | cut -d\  -f2 | head -1

虽然我能够联系上,但我对情况产生了误解。为什么连接不起作用localhost?为什么我描述的第二种方法有效?无论如何,这个命令有什么意义呢ifconfig -u | grep 'inet ' | grep -v 127.0.0.1 | cut -d\ -f2 | head -1?

我有Mac系统

postgresql
  • 1 个回答
  • 44 Views
Martin Hope
rew
Asked: 2023-08-19 19:46:31 +0000 UTC

导入math模块时,None对象的引用数量减少

  • 16

我注意到一个有趣的行为,但我无法理解。

导入模块时,math对象引用的数量None会减少:

import sys

print(sys.getrefcount(None))
import math
print(sys.getrefcount(None))

结论:

4138
4099

为什么会发生这种情况变得很有趣。如果有人能解释我会很高兴)

python
  • 2 个回答
  • 156 Views
Martin Hope
rew
Asked: 2022-12-30 02:06:16 +0000 UTC

无法在 Nullable C# 中分配 null

  • 6

此代码无法编译:

public static void f<T>()
{
    T? a = null;
}

错误

Cannot convert 'null' to type parameter 'T' because it could be a value type. Consider using 'default(T)' instead

为什么会这样?

c#
  • 1 个回答
  • 27 Views
Martin Hope
rew
Asked: 2022-12-26 01:35:51 +0000 UTC

在 C# 中是否有来自 Go 的延迟模拟

  • 5

有类似的C#东西吗?deferGo

你Go可以这样做,例如:

func f() {
    defer return stack.Top(); // Указываем значение, которое нужно вернуть
    stack.Pop(); // Удаляем элемент. Но функция все равно вернет его значение
}
c#
  • 1 个回答
  • 35 Views
Martin Hope
rew
Asked: 2022-12-09 01:34:40 +0000 UTC

将数组元素作为单独的参数传递给函数。C#

  • 5

如何将数组元素作为单独的参数传递给函数?

你可以这样做:

f(arr[0], arr[1], arr[2])

但这并不总是很方便。

Python你可以这样做:

f(*arr)

C#出于某种原因,我找不到如何去做。

c#
  • 1 个回答
  • 39 Views
Martin Hope
rew
Asked: 2022-08-18 20:30:11 +0000 UTC

使用两个相互调用的递归函数

  • 0

假设我们有以下代码(稍微修改了 dfs):

#include <iostream>
#include <vector>

using namespace std;

vector <int> vec[100];
bool used[100];
int n;

void dfs(int v){
    if (used[v])
        return ;

    used[v] = true;

    for (int to : vec[v])
        if (to < v) {
            cout << "first action\n";
            cout << "second action\n";
            cout << "third action\n";

            dfs(to);
        }

    for (int to : vec[v])
        if (to > v) {
            cout << "first action\n";
            cout << "second action\n";
            cout << "third action\n";

            dfs(to);
        }
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            int q;
            cin >> q;
            if (q)
                vec[i].push_back(j);
        }
    }

    dfs(1);

    return 0;
}

针迹

cout << "first action\n";
cout << "second action\n";
cout << "third action\n";
dfs(to);

被重复 2 次,因此将它们移动到一个函数中是合乎逻辑的。原来这段代码:

#include <iostream>
#include <vector>

using namespace std;

vector <int> vec[100];
bool used[100];
int n;

void f(int to){
    cout << "first action\n";
    cout << "second action\n";
    cout << "third action\n";

    dfs(to);
}

void dfs(int v){
    if (used[v])
        return ;

    used[v] = true;

    for (int to : vec[v])
        if (to < v) {
            f(to);
        }

    for (int to : vec[v])
        if (to > v) {
            f(to);
        }
}

int main() {
    cin >> n;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            int q;
            cin >> q;
            if (q)
                vec[i].push_back(j);
        }
    }

    dfs(1);

    return 0;
}

但是,由于显而易见的原因,它不起作用。

当然,您可以只在函数中添加 3 行:

cout << "first action\n";
cout << "second action\n";
cout << "third action\n";

这个选项有效。但是仍然有重复的代码:

f();
dfs(to);

我是否正确理解在这种情况下不可能摆脱这种重复?

c++
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2022-06-11 01:49:07 +0000 UTC

在窗户上绘图

  • 0

我想制作一个可以在窗口顶部绘制的 Python 程序。

换句话说,您可以这样做:在此处输入图像描述

我了解如何跟踪鼠标的位置和点击。但我不知道如何在其他窗口上绘图(有人可以帮忙吗?

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2022-04-02 20:18:49 +0000 UTC

Pyinstaller 无法构建程序

  • 0

有工作代码可以使用pynput.

from pynput import keyboard


def on_press(key):
    print('press', key)


if __name__ == '__main__':
    t = keyboard.Listener(on_press=on_press).start()
    input('Press Enter to close program')

如果使用 help 构建它pyinstaller,则启动时会出现错误: 在此处输入图像描述

Windows 10、Python3.7.6、Pyinstaller 4.2

如何解决这个问题?

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2022-03-25 01:54:19 +0000 UTC

PyQt5按键事件未被捕获

  • 2

我正在PyQt5中制作应用程序。我有这个窗口:

在此处输入图像描述

我想用来keyPressEvent拦截这个窗口中的所有击键。我拦截了大多数击键,但是当您按下小键盘上的箭头时,此方法不起作用,因为它不被视为按键事件,而是其他一些突出显示按钮的事件。

图片显示该按钮以虚线突出显示:

在此处输入图像描述

如果按钮被移除,那么所有的键都被正确拦截。

我怎样才能解决这个问题并拦截所有击键?

from PyQt5.QtWidgets import *
import sys


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.resize(430, 130)

        self.label = QLabel(self)
        self.label.setText('Нажмите на клавиатуре нужное вам сочетание клавиш')
        self.label.resize(400, 50)
        self.label.move(10, 10)

        self.button = QPushButton(self)
        self.button.setText('Создать сочетание клавиш')
        self.button.resize(400, 50)
        self.button.move(10, 50)

    def keyPressEvent(self, event):
        print('press')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2022-03-24 20:43:24 +0000 UTC

获取按键Python的字符[关闭]

  • 1
关闭。这个问题需要澄清或补充细节。目前不接受回复。

想改进这个问题?通过编辑此帖子添加更多详细信息并澄清问题。

1 年前关闭。

改进问题

获得按键的按键并不难。
但是有可能得到按键的字符吗?

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2022-02-08 20:09:33 +0000 UTC

pyqt5背景颜色变化动画

  • 1

我想实现闪光功能。背景颜色应该改变为新的,然后顺利返回。

我确实喜欢这样:

from IPython.external.qt_for_kernel import QtGui
from PyQt5.QtGui import QColor, QBrush
from PyQt5.QtWidgets import *
import sys
from copy import copy, deepcopy
from classes.statistics import Statistics
from PyQt5.QtCore import QTimer, Qt


class MainWindow(QMainWindow):
    def __init__(self, width=900, height=900, font_size=20, input_size=(25, 30), background_color=[60, 170, 255],
                 red=[255, 0, 0], green=[0, 255, 0]):
        super().__init__()

        self.width, self.height = width, height
        self.resize(width, height)

        self.background_color = background_color
        self.red = red
        self.green = green

        self.setupUi()

    def flash(self, start_color, time=5000, step=100):
        steps = [(self.background_color[i] - start_color[i]) / time * step for i in range(3)]
        print('steps =', steps)
        current_color = copy(start_color)

        for i in range(0, time, step):
            QTimer.singleShot(i, lambda: self.set_color(copy(current_color)))
            print(f'{i} ms before {current_color}')
            for i in range(3):
                current_color[i] += steps[i]

    def red_flash(self, time=5000, step=100):
        self.flash(self.red, time=time, step=step)

    def green_flash(self, time=5000, step=100):
        self.flash(self.green, time=time, step=step)

    def set_color(self, color):
        print('setting color', color)
        self.palette.setColor(QtGui.QPalette.Background, QColor(*color))
        self.setPalette(self.palette)
        self.show()

    def setupUi(self):
        self.palette = QtGui.QPalette()
        self.palette.setColor(QtGui.QPalette.Background, QColor("#99ccff"))
        self.setPalette(self.palette)

        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWindow()
    w.show()
    w.red_flash()
    sys.exit(app.exec_())

如果您查看程序的输出:

0 ms before [255, 0, 0]
100 ms before [190.0, 56.666666666666664, 85.0]
200 ms before [125.0, 113.33333333333333, 170.0]
setting color [60.0, 170.0, 255.0]
setting color [60.0, 170.0, 255.0]
setting color [60.0, 170.0, 255.0]

你可以看到函数被调用了几次set_color,颜色不同,但是当函数开始运行时,每次都使用相同的颜色。

可能是什么问题呢?

也许我选择了错误的方法来实现这个想法,还有另一种更正确的方法吗?

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2022-02-07 21:38:14 +0000 UTC

QLineEdit PyQt5 中的文本更新问题

  • 1

我正在编写一个小型应用程序,我需要在用户在输入框中输入内容后立即运行某个功能。

我是这样实现的:

from PyQt5.QtWidgets import *
import sys
from time import sleep


def function():
    sleep(2)


class Input(QLineEdit):
    def __init__(self, main_window):
        super().__init__(main_window)
        self.main_window = main_window

    def keyPressEvent(self, event):
        super().keyPressEvent(event)
        function()


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setupUi()

    def setupUi(self):
        self.input = Input(self)
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MainWindow()

    w.show()

    sys.exit(app.exec_())


问题是Input用户输入的文字并没有立即出现,而是在函数执行后才出现,不是很方便。

如何解决这个问题?

python
  • 2 个回答
  • 10 Views
Martin Hope
rew
Asked: 2021-12-09 03:13:56 +0000 UTC

无法收缩磁盘分区

  • 1

我想dev/sda5使用 GParted 缩小分区在此处输入图像描述

但这对我不起作用,按钮Resize未激活。滑块也不能移动。

在此处输入图像描述

我在 Clear Linux 上

有人可以告诉我问题是什么以及如何解决吗?

linux
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2021-11-29 23:25:50 +0000 UTC

长跑距离C++函数

  • 0

有一个代码:

for (int i = 0; i < n; i++){
    cout << "i =  " << i << endl;
    cin >> q;
    cout << "q = " << q << endl;
    st.insert(q);
    cout << "inserted" << endl;
    curr_right += distance(st.lower_bound(q), st.begin());
    cout << "end of for\n";
}

进入这样的测试时

5
5 4 2 3 1

程序显示的最后一件事

q = 3
inserted

然后它什么也不显示,也没有结束。

也就是说,插入set发生了,但函数的distance行为却很奇怪。

可能是什么问题呢?

c++
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2021-10-20 19:50:38 +0000 UTC

Arduino 发送一个额外的字符

  • 1

有这个代码:

void setup() {
  Serial.begin(9600);
  Serial.print("Start");

}

void loop() {
  if (Serial.available() > 0){
    int in_data = Serial.read();
    Serial.println(in_data);
    Serial.println("----");
  }
}

它接受字符并发送回它们的代码。但除了发送字符的代码外,它还发送数字 10,如果我理解正确,它会在某处找到换行符。这是发送信件时的输出示例z。

122
----
10
----

这个问题很容易用一个 if 解决,但我仍然有兴趣知道 arduino 找到一个额外字符的原因。我观看视频的 youtuber 工作正常。

我有arduino uno。

arduino
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2020-09-09 15:45:49 +0000 UTC

pipereqs ubuntu 不工作

  • 0

pipreqs为安装python3,但写道找不到该命令

但我可以从 python 导入库: 在此处输入图像描述

我正在运行 Ubuntu 20.04。

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2020-08-14 17:35:48 +0000 UTC

如何学习神经网络

  • 0
关闭。这个问题不可能给出客观的答案。目前不接受回复。

想改进这个问题? 重新构建问题,以便可以根据事实和引用来回答。

2年前关闭。

改进问题

我最近开始学习神经网络。现在我正在尝试在不使用第三方库的情况下编写自己的神经元。我能够教她区分三和四,但不知怎的,我无法教她识别其他数字,在我的代码中的某个地方存在问题。

我听说有些库据说pytorch有现成的代码。所以我有一个问题,如果有现成的解决方案,是否值得自己学习编写神经网络,它会给我一些东西吗?

python
  • 2 个回答
  • 10 Views
Martin Hope
rew
Asked: 2020-08-01 03:09:49 +0000 UTC

requests.get() 收到的代码与页面代码不同

  • 1

我正在尝试获取此页面的代码,如下所示:

import requests

if __name__ == '__main__':
    response = requests.get('https://www.rusplitka.ru/catalog/plitochnyy-kley-zatirka/')
    print(response.text)

基本上,代码是正确的,但是每个产品都有一个铭文:是否有库存。我在 python 的帮助下收到的代码中没有这样的东西。

可能是什么问题呢?也许这些铭文不是立即加载的,而是页面加载后的一段时间?

python
  • 1 个回答
  • 10 Views
Martin Hope
rew
Asked: 2020-07-31 01:14:32 +0000 UTC

格式化 Ubuntu 磁盘分区

  • 1

我有多个分区在此处输入图像描述

我想放大的 dev/sda5 上的那个。本节前有空格。如何将此可用空间添加到 dev/sda5?该程序不允许您这样做:由于分区较高,因此无法增加分区的大小,也无法移动分区。

ubuntu
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5