RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

全部问题

Martin Hope
Т. Н
Asked: 2024-10-21 01:50:22 +0000 UTC

Python 版本输出不正确

  • 5

我对这项任务得出了错误的结论:

检查Python解释器的版本:如果版本为3.11及更高版本,则在单独的行中打印对名为attribute的变量的引用数量以及它在内存中占用的字节数。

如果版本为 3.10 或更低,则在单独的行中打印脚本的名称以及运行脚本时通过命令行传递的参数数量。

我有 python 3.12,所以我的代码如下所示(但在验证时抛出错误):

import sys
attribute = [] #непонимаю, как должна выглядеть эта строка ввода
print (sys.getrefcount(attribute))
print (sys.getsizeof(attribute))

例如(应该在输出中执行什么):

测试:

attribute = 10**10 + 1

sys.version = '3.11.5'

结果:

4

32
python
  • 1 个回答
  • 90 Views
Martin Hope
Daniel Batura
Asked: 2024-10-21 01:11:20 +0000 UTC

将鼠标悬停在内容上的轮播[关闭]

  • 4
关闭。这个问题需要澄清或者补充细节。目前不接受对此问题的答复。

想要改进这个问题吗?通过编辑这篇文章添加更多详细信息并澄清问题。

17 小时前关闭。

改进问题

其中有块的部分,当它们悬停在该部分的左侧时,应该滚动到左侧,相应地,也应该滚动到右侧。

我在网上搜索了很多,找不到解决这个问题的方法。我会自己用js写,但我不太擅长:(

javascript
  • 2 个回答
  • 43 Views
Martin Hope
amonus1245
Asked: 2024-10-20 22:47:24 +0000 UTC

如何为带有动画的按钮在窗口中设置特定的坐标和大小?

  • 6

无名.py:

from PyQt5 import QtCore, QtGui, QtWidgets
from b import FlyButton


class Ui_MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi()

    def setupUi(self):
        self.setObjectName("self")
        self.resize(612, 427)
    
        self.pusButton = FlyButton()
        self.pusButton.setGeometry(QtCore.QRect(270, 192, 51, 41))
        self.pusButton.setText("")
        self.pusButton.setObjectName("pusButton")
        self.setCentralWidget(self.pusButton)
        self.statusbar = QtWidgets.QStatusBar(self)
        self.statusbar.setObjectName("statusbar")
        self.setStatusBar(self.statusbar)

这里,有一些代码创建了带有某种动画的按钮,并且该按钮应该位于正确的位置,而不是位于整个窗口上。 (这是使用PyQt5 UI 代码生成器 5.15.9
生成的代码。我尝试保留此生成的代码并将其分配给另一个文件,但它不起作用。 我不明白为什么?我只是想知道如何使它不出现在整个窗口上?)FlyButton()self.pusButton


b.py:

from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QPropertyAnimation, QEasingCurve
from PyQt5 import QtCore 


class FlyButton(QPushButton):
    def __init__(self, *args, **kwargs):
        super().__init__()
        self.animation = QPropertyAnimation(self, b'size')
        self.animation.setDuration(2000)
        self.animation.setEasingCurve(QEasingCurve.OutInElastic)

    def enterEvent(self, event):
        self.animation.setStartValue(self.size())    
        self.animation.setEndValue(QtCore.QSize(300, 250,))

        self.animation.start()
        QPushButton.enterEvent(self, event)
        print('работает')

这是用户界面本身:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>612</width>
    <height>427</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QPushButton" name="pushButton">
    <property name="geometry">
     <rect>
      <x>270</x>
      <y>192</y>
      <width>51</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string/>
    </property>
   </widget>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>
python
  • 1 个回答
  • 35 Views
Martin Hope
User12351259599491
Asked: 2024-10-20 21:48:19 +0000 UTC

Http 请求在 Postman 和 PowerShell 中通过,但在 C# httpclient 中失败

  • 6

主题

这是在Postman中导入的CURL请求

curl --location 'https://api.telegra.ph/createPage' \
--header 'Content-Type: application/json' \
--data '{"access_token":"26fb54ae0ace42a66d743ec00519a604236dca21e80b588d012833b6955d", "title": "Mytitle", "content": [{"tag": "p", "children": ["Hello, world!"]}]}'

回答 在此输入图像描述 另外,请求通过 PowerShell

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/json")

$body = @"
{`"access_token`":`"26fb54ae0ace42a66d743ec00519a604236dca21e80b588d012833b6955d`", `"title`": `"Mytitle`", `"content`": [{`"tag`": `"p`", `"children`": [`"Hello, world!`"]}]}
"@

$response = Invoke-RestMethod 'https://api.telegra.ph/createPage' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

这是生成 POSTMAN 的C# 代码https://dotnetfiddle.net/eRJHRN ,

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.telegra.ph/createPage");
var content = new StringContent("{\"access_token\":\"26fb54ae0ace42a66d743ec00519a604236dca21e80b588d012833b6955d\", \"title\": \"Mytitle\", \"content\": [{\"tag\": \"p\", \"children\": [\"Hello, world!\"]}]}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());

答案来了:

{"ok":false,"error":"ACCESS_TOKEN_INVALID"}

据说不是有效的令牌。

为什么会这样呢?

c#
  • 1 个回答
  • 55 Views
Martin Hope
Handler
Asked: 2024-10-20 21:08:23 +0000 UTC

智能依赖注入

  • 5

我有一个小型库,我可以从网站获取一些数据,然后将其序列化。

我知道正确的开发方式是采用依赖注入的原理。在我的代码中有一个特定的基类,其中包含所有可用的方法。

class MyClass:
    def __init__(self):
        self.my_http_connection = HttpConnection()
    def my_method(self):
        return self.my_http_connection.get("address")

library = MyClass()

library.my_method()

在构造函数中,我创建了一个实例HttpConnection,事实上,我还有更多这样的实例,它们负责完全不同的情况。例如,哈希类。

以这种方式在构造函数中初始化类是否正确?这是好的做法吗?我阅读了 redis-py 和 aiogram 的源代码,这些东西是以完全不同的方式实现的。例如,aiogram 库中的任何方法都是通过__call__.有条件地

async def send_message(self):
    call = SendMessage()
    await self(call)

正因为如此,我不知道应该朝哪个方向去了解如何编写好的代码。

upd:我忘了提及我也分担课程的责任。我不会在一堂课上完成数学、http 请求和数据库工作。一个真实的例子如下所示:

class Explorer:
    def __init__(self, connection: Http):
        self.conn = connection

    def get(url):
        return self.conn.get(url)

class MyClass:
    def __init__(self):
        self.my_http_connection = Http()
        self.serializer = Serializer()
        self.explorer = Explorer(self.my_http_connection)
    def my_method(self):
        return self.serializer.serialize(self.explorer.get("address"))

library = MyClass()

library.my_method()

这就是我实现几乎所有代码的方式。而在explorer类中,以此类推,可能还有另一个类负责某事等等。

python
  • 1 个回答
  • 69 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