RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

helldrg's questions

Martin Hope
helldrg
Asked: 2022-07-20 21:32:20 +0000 UTC

如何将字符串转换为整数

  • 0

如何正确执行这样的代码?现在它使用 '??' 引发错误合并 当可选值包含 'nil 时提供默认值

var s = "5"
var num = Int(s) + 1
print(num)

PS:就实现在线工作、连接到服务器、将数据加载到本地数据库以及之后能够离线工作的应用程序的关键模式和库提供建议。使用MVVM模式,基于Core Data制作本地数据库?

swift ios
  • 1 个回答
  • 32 Views
Martin Hope
helldrg
Asked: 2022-07-12 22:18:25 +0000 UTC

将地址解析为组件

  • 1

有一个地址列表,例如:

Абрамцевская улица, дом 16 Б
ул. Абрамцевская, д.3
ул Абрамцевская 5
Абрамцевская ул., 5/2

还有一个类:

class Address:
    def __init__(self, type, type_house, number_house):
        self.type = type # улица или шоссе
        self.name = name # название улицы
        self.type_house = 'дом' 
        self.number_house = number_house # все, что справа от названия улицы

如何将字符串拆分为类的组件字段Address?我尝试通过用符号分割字符串中的单词,然后循环遍历结果列表以搜索关键字,例如ул, улица等。然后按关键字搜索дом, д。根据元素的索引或不存在,我找到了街道的名称。不知何故,一切都不是很笨拙,也许有人有更有趣的实现选项

python
  • 1 个回答
  • 235 Views
Martin Hope
helldrg
Asked: 2022-06-13 19:50:08 +0000 UTC

创建所有列表组合

  • 0

有一个清单:

l = [1, 2, 3, 4, 5]

如何重建数组以使元素处于所有可能的组合中?

print(l) # [1, 2, 3, 4, 5]
print(l) # [1, 2, 3, 5, 4]
print(l) # [1, 2, 5, 3, 4]

ETC

python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-06-11 17:05:43 +0000 UTC

用另一个对象重载一个对象的赋值运算符

  • 0

如何重新定义赋值运算符,以便将一个对象的值分配给另一个对象,例如:

class Obj1():
  def __init__(self, x, y):
    self.x = x
    self.y = y

class Obj2():
  def __init__(self, x, y, z):
    self.x = x
    self.y = y
    self.z = z
  
a = Obj1(1,2)
b = Obj2(0, 0, 0)
b = a 
# в b должны быть значения 1, 2, 0
python
  • 3 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-04-16 21:54:48 +0000 UTC

遇到给定字符之一时如何拆分字符串?

  • 2

如何在第一次遇到这些字符时拆分字符串:

' ', ')', 'a', '3'

除了拼写这个句子,我想不出别的了。

python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-03-13 17:51:39 +0000 UTC

是否可以增加公交车站和地铁的标准图标

  • 0

是否可以增加标准的公交车站和地铁图标?

yandex-maps-api
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-10-08 00:45:39 +0000 UTC

如何从 Post 中获取数据

  • 0

有这个代码:

@method_decorator(login_required, name='dispatch')
class MainFormView(DataMixin, FormView):
form_class = MainForm
template_name = 'sitee/index.html'
success_url = reverse_lazy('home')

def get_context_data(self, *, object_list=None, **kwargs):
    context = super().get_context_data(**kwargs)
    context['menu_selected'] = 'home'
    c_def = self.get_user_context(title="Главная")
    return dict(list(context.items()) + list(c_def.items()))

def form_valid(self, form):
    # print(POST)
    #context['result'] = POST['title']
    return redirect('home')

#index.html
<form method="post">
{% csrf_token %}
<div class="form-error">{{ form.non_field_errors }}</div>
<input id="title" name="title" type="text"/>
<input id="datetime" name="datetime" type="text"/>
    <label for="id_groups_0">
        <input type="checkbox" name="groups" value="0" id="id_groups_0">
        Группа 2
    </label>
    <label for="id_groups_1">
        <input type="checkbox" name="groups" value="0" id="id_groups_1">
        Группа 1
    </label>
<button type="submit">Отправить</button>
</form>
{{result}}

当您点击主页时,会出现此表单。点击“提交”后如何显示来自 post 请求的数据,将 post['title'] 中的值添加到上下文中并显示在页面上

django
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-10-07 17:52:45 +0000 UTC

如何将django部署到服务器

  • 0

有一个 ubuntu 操作系统服务器。我下载了python,做了一个虚拟环境,下载了django,创建了一个项目,迁移了数据库,启动了。服务器在 127.0.0.1:8000 运行。我无法检查它在本地是否真的有效,因为服务器是远程的。问题是,我通过交互式控制台启动服务器,如果我关闭控制台,服务器也会关闭,据我所知。如何启动它以使其始终有效?以及如何运行它,以便您不仅可以从本地访问该站点,还可以从远程计算机访问该站点。

django
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-10-06 18:01:03 +0000 UTC

拉伸右侧列表以适合左侧

  • 0

.p-layout {
                    display: flex;
                    flex-direction: column;
                }

                .p-content {
                    display: flex;
                    flex-direction: row;
                    
                    justify-content: center;
                    align-content: space-between;
                    padding-top: 30px;
                }

                .p-content ul{
                    background-color: #f9f9f9;
                }

                .p-content ul li {
                    padding: 10px;
                }

                .p-content-col {
                    display: flex;
                    flex-direction: column;
                    height: 100%;
                }

                .p-content-label {
                    margin-left: 30px;
                }

                .p-content-btn-box {
                    display: flex;
                    flex-direction: row;

                    justify-content: center;

                    padding: 10px;
                    margin: 0 auto;
                }

                .btn-param {
                    width: 80px;
                    padding: 10px;  
                }
            <div class="p-layout">
                <div class="p-content">
                    <div class="p-content-col">
                        <div>
                        <label class="p-content-label" for="">Заголовок: </label>
                    </div>
                        <div>
                        <ul id="id_groups">
                            <li>
                                <label for="id_groups_0">
                                    <input type="checkbox" name="groups" value="0" id="id_groups_0">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_groups_1">
                                    <input type="checkbox" name="groups" value="1" id="id_groups_1">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_groups_2">
                                    <input type="checkbox" name="groups" value="2" id="id_groups_2">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_groups_3">
                                    <input type="checkbox" name="groups" value="3" id="id_groups_3">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_groups_4">
                                    <input type="checkbox" name="groups" value="4" id="id_groups_4">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_groups_5">
                                    <input type="checkbox" name="groups" value="5" id="id_groups_5">
                                    Элемент
                                </label>
                            </li>
                        </ul>
                        </div>
                        <div class="p-content-btn-box">
                            <div class="btn-param">Отправить</div>
                            <div class="btn-param">Отправить</div>
                        </div>
                    </div>
                    <div class="p-content-col">
                        <label class="p-content-label" for="">Заголовок: </label>
                        <ul id="id_sources">
                            <li>
                                <label for="id_sources_0"><input type="checkbox" name="sources" value="0"
                                        id="id_sources_0">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_sources_1"><input type="checkbox" name="sources" value="1"
                                        id="id_sources_1">
                                    Элемент
                                </label>
                            </li>
                            <li>
                                <label for="id_sources_2"><input type="checkbox" name="sources" value="2"
                                        id="id_sources_2">
                                    Элемент
                                </label>
                            </li>
                        </ul>
                        <div class="p-content-btn-box">
                            <div class="btn-param">Отправить</div>
                            <div class="btn-param">Отправить</div>
                        </div>
                    </div>
                </div>
            </div>

如何将右侧列表扩展到左侧列表的级别? 在此处输入图像描述

html
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-10-06 17:44:55 +0000 UTC

如何运行程序

  • 1

php 中有一个命令exec,但是 django 中有一个类似的命令吗?是否可以从 static/program.exe 文件夹运行?

python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-10-06 15:31:39 +0000 UTC

从多个重定向到一个页面

  • 0

有这个代码:

#urls.py
path('', MainFormView.as_view(), name='home'),
path('index', MainFormView.as_view(), name='home'),
path('home', MainFormView.as_view(), name='home'),
...
#base.html
{% if request.path == '/home' %}
    {{ блок }}
{% endif %}

一页有多个地址。此页面应显示一个块,但条件是一种方式。如何在条件中不枚举的情况下简洁地做到这一点?或者如何从第一条和第二条路径重定向到第三条?

UDP代码view:

@method_decorator(login_required, name='dispatch')
class MainFormView(DataMixin, FormView):
    form_class = MainForm
    template_name = 'sitee/index.html'
    success_url = reverse_lazy('home')

    def get_context_data(self, *, object_list=None, **kwargs):
        context = super().get_context_data(**kwargs)
        context['menu_selected'] = 'home'
        c_def = self.get_user_context(title="Главная")
        return dict(list(context.items()) + list(c_def.items()))

    def form_valid(self, form):
        print(form.cleaned_data)
        return redirect('home')

可以通过三种方式访问​​该页面:

127.0.0.1
127.0.0.1/index
127.0.0.1/home

如何使当你尝试去127.0.0.1而127.0.0.1/index我们被转移到127.0.0.1/home?这是必要的,这样模板才会有这样的条件if request.path == '/home',而不是这样。if request.path == '/home' or request.path == '/index' or request.path == '/'

或者你可以不做重定向就离开它,并在条件中使用类似这样的东西:if request.name == 'home',即 如果指定了页面名,不管它的路径是什么,都满足条件

django
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-10-05 14:50:13 +0000 UTC

AuthenticationForm 中的记住按钮

  • 0

有这个代码:

class LoginUserForm(AuthenticationForm):
username = forms.CharField(label='Логин', widget=forms.TextInput(attrs={'class': 'form-input', 'placeholder': 'Username'}))
password = forms.CharField(label='Пароль', widget=forms.PasswordInput(attrs={'class': 'form-input', 'placeholder': 'Password'}))
...
class LoginUser(DataMixin, LoginView):
form_class = LoginUserForm
template_name = 'iviolations/login.html'

def get_context_data(self, *, object_list=None, **kwargs):
    context = super().get_context_data(**kwargs)
    c_def = self.get_user_context(title="Авторизация")
    return dict(list(context.items()) + list(c_def.items()))

def get_success_url(self):
    return reverse_lazy('home')
...
 <form method="post">
        {% csrf_token %}
    
        <div class="form-error">{{ form.non_field_errors }}</div>
        
        {% for f in form %}
        <label class="form-label" for="{{ f.id_for_label }}"></label>{{ f }}
        <div class="form-error">{{ f.errors }}</div>
        {% endfor %}
    
        <button type="submit">Войти</button>
    </form> 

如何添加记住按钮?

django
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-09-23 20:53:07 +0000 UTC

跟踪标签的消失

  • 0

有这个代码:

# Пока таблица находится на странице
while True:
  # Ищем таблицу
  if not driver.find_element_by_xpath('//*[@id="main-container"]/table'):
    # Если она пропала нажимаем на ссылку и выходим из цикла ожидания
    link = driver.find_element_by_link_text('Ссылка')
    link.click()
    break
  else:
    # Иначе ждем две секунды и проверяем снова, пропала таблица или нет
    time.sleep(2)

我想使用该功能WebDriverWait,但事实证明,堆积自行车比弄清楚它要快。目前的问题是,当表格消失时,出现错误:

消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"// [@id="main-container"]/table"}*

如何安全地检查页面上是否存在元素?并且可以根据以下代码转换此代码WebDriverWait

python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-09-03 16:48:19 +0000 UTC

如何编写带有标题的 .xlsx 表格文件?

  • -2

我正在使用这段代码:

df = pd.DataFrame.from_dict(self.table)
df.sort_values(by=['id'], ascending=False)
df.style.set_caption("Заголовок таблицы")
df.to_excel(path+"test.xlsx", sheet_name="sheet111", index=False)

但是标题没有出现。

python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-08-31 22:42:37 +0000 UTC

如何在 QDateTimeEdit 中更改时间

  • 0

有一个date类型为 的变量QDateTimeEdit。

date.dateTime()有类型QDateTime。

如何增加或减少几天或几小时?

python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-08-31 20:16:06 +0000 UTC

从列表中按索引提取字典

  • 1

我有以下字典和列表:

groups = {
    "group1" : [
        77, 88, 99
    ],
    "group2" : [
        11, 22, 33, 44, 55, 66
    ],
    "group3" : [
        1, 2, 3, 4, 5
    ]
}
types = [True, False, True]
...
list = []

如何在与列表list中的值对应的索引处写下字典的所有值 在这个例子中,它应该可以 工作。目前我只能通过if-s来实现Truetypeslist = [77, 88, 99, 1, 2, 3, 4, 5]

python
  • 3 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-08-27 20:45:13 +0000 UTC

如何将列表添加到字典

  • 1

如何将列表添加到字典中?我这样理解

table = {}
idd = []
name = []
address = []


for i in range(2):
    idd.append(i)
    name.append(i+1)
    address.append(i+2)

table = table | { 
        "idd" : idd,
        "name" : name,
        "address" : address
    }
    
print(table["address"][1])

在我看来,在我的版本中有很多多余的东西,我怎么能写得更短呢?

python
  • 2 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-08-16 23:04:43 +0000 UTC

剪切部分句子,更改并粘贴回来[关闭]

  • -1
关闭。这个问题需要具体说明。目前不接受回复。

你想改进这个问题吗? 重新构建问题,使其只关注一个问题。

1 年前关闭。

改进问题

有一个提议:

"Sum(Dictonary((12 30, 46 72, 87 1043)), Dictonary(1 1, 439534 431213.343, 4343 3)))"

如何获取数组:

[["12 30", "46 72", "87 1043"], ["1 1", "439534 431213.343", "4343 3"]]

例如,将一个元素添加到这些数组中并插入回句子中

我正在尝试使用这样的正则表达式查找元素的位置,但它适用于单词,但不适用于两个括号:

r'\((([^]]+))\)'

通过函数re.findall

UDP:这个选项更接近,但有额外的括号

^\(\((((?!\[)(?!\]).)+)\)\)

对于主持人:充实问题是什么意思?

python
  • 2 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-06-25 01:14:53 +0000 UTC

如何在类中包装处理程序和装饰器函数

  • 0

如何将以下代码包装在一个类中:

import telebot

bot = telebot.TeleBot('...')

if __name__ == '__main__':
    #Tele = Telegram()
    #Tele.run()
    
    @bot.message_handler(commands=['start'])
    def start_command(message):
        bot.send_message(message.chat.id, "Hello!")
    bot.polling()
    

最终结果应该是这样的:

import telebot

class Telegram():
    def __init__(self):
        self.token = '...'
        self.bot = telebot.TeleBot('...')
    
        @self.bot.message_handler(commands=['start'])
        def start_command(self, message):
            self.bot.send_message(message.chat.id, "Hello!")
    
    def run(self):
        self.bot.polling()


if __name__ == '__main__':
    Tele = Telegram()
    Tele.run()
python
  • 1 个回答
  • 10 Views
Martin Hope
helldrg
Asked: 2022-06-04 02:41:33 +0000 UTC

调用更新函数更新paintEvent

  • 1

是否有任何选项可以在不冻结界面的情况下每秒执行paintEvent一次该功能?30

from typing import Sized
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QRadialGradient, QPainter, QPainterPath, QPen, QBrush, QGradient, QColor
from PyQt5.QtCore import QPointF, Qt, QRect
import sys

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        
        self.centralwidget = QtWidgets.QWidget()
        self.setCentralWidget(self.centralwidget)
        self.resize(600, 400)
       
    def paintEvent(self, event):
        self.painter = QPainter(self)
        
        radialGrad = QRadialGradient(QPointF(300, 450), 200)
        
        radialGrad.setColorAt(0, QColor('#1B2735'))
        radialGrad.setColorAt(1, QColor('#090A0F'))

        self.painter.setBrush(radialGrad)
        self.painter.drawRect(0, 0, 600, 400) 

        self.painter.setBrush(QBrush(Qt.white))

        self.painter.drawRect(100, 390, 2, 2) 
        self.painter.drawRect(200, 390, 3, 3) 
        self.painter.drawRect(300, 390, 4, 4)
        self.update()

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    w = MainWindow()
    w.show()
    sys.exit(app.exec_())
python
  • 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