RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

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

Duncan's questions

Martin Hope
Duncan
Asked: 2023-10-19 22:52:17 +0000 UTC

删除 Matplotlib 绘图轴值中的月份集合

  • 5

需要在图表的 x 轴上以俄语显示月份名称。
我这样做:

import datetime
import locale
from matplotlib import dates as mpl_dates
from matplotlib import pyplot as plt

dates = [
    datetime.date(2021, 10, 21),
    datetime.date(2021, 8, 25),
]
y = [0, 1]
plt.plot_date(dates, y)
plt.gca().xaxis.set_major_locator(mpl_dates.MonthLocator())
plt.gca().xaxis.set_major_formatter(mpl_dates.DateFormatter('%B'))
locale.setlocale(locale.LC_ALL, "ru_RU.utf8")
plt.show()

在图表的标题中,我收到了俄语月份的名称,但是是所有格。 在此输入图像描述

如何获得主格中的月份名称?

附言。我还尝试通过 pandas 获取月份的名称:

dt.month_name(locale="ru_RU.utf8")

但结果是一样的。显然机制是一样的。

python
  • 1 个回答
  • 50 Views
Martin Hope
Duncan
Asked: 2022-07-16 16:43:31 +0000 UTC

如何修复 YAML 中逐字标记的显示问题?

  • 1

我正在尝试创建 yaml

import sys
from ruamel.yaml import YAML

class Entry:
    yaml_tag = '!<!entry>'

    def __init__(self, value, style=None):
        self.value = value
        self.style = style

    @classmethod
    def to_yaml(cls, representer, node):
        return representer.represent_mapping(cls.yaml_tag, node.value, node.style)

    @classmethod
    def from_yaml(cls, constructor, node):
        return cls(node.value, node.style)

data = {
    'steps': [
        Entry({
            'id': 'Entry-1',
            'actions': [],
        })
    ],
}

yaml = YAML(typ='rt')
yaml.register_class(Entry)
yaml.dump(data, sys.stdout)

但在输出中,!<!entry>我得到了!%3C%21entry%3E.

steps:
- !%3C%21entry%3E
  id: Entry-1
  actions: []
python yaml
  • 1 个回答
  • 31 Views
Martin Hope
Duncan
Asked: 2020-11-29 05:52:12 +0000 UTC

SIOCDDRT:网络不可用

  • 1

我正在尝试完成以下任务:
指定 route 命令的参数,为 8 个地址配置到网络 192.168.5.0 子网的路由
我这样做:

route add -net 192.168.5.0 netmask 255.255.255.248 gw 192.168.5.1

我收到一个错误:SIOCADDRT: Сеть недоступна
怎么了?

结论route -n:

route -n
Таблица маршутизации ядра протокола IP
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    600    0        0 wlp3s0f0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlp3s0f0
192.168.0.0     0.0.0.0         255.255.255.0   U     600    0        0 wlp3s0f0
route
  • 1 个回答
  • 10 Views
Martin Hope
Duncan
Asked: 2020-09-15 07:24:40 +0000 UTC

常用表达。相交序列

  • 1

如何从字符串中选择所有必要的序列,包括相交的序列?
如果我这样做:

re.findall('\d{3}', '123456')

然后它输出:['123', '456']

如何使其输出:['123', '234', '345', '456']?

python
  • 1 个回答
  • 10 Views
Martin Hope
Duncan
Asked: 2020-09-14 14:27:02 +0000 UTC

如何将 lambda 作为参数传递给生成器?

  • 0

我正在尝试这样做:

foo = lambda x: x > 0
lst = [-2, 1, 0, -5, 8]

filtered_lst = [x for x in lst if foo ]
print(filtered_lst)

不工作。
虽然它是这样工作的:

filtered_lst = list(filter(foo, lst))
print(filtered_lst)

问题是什么?

python
  • 1 个回答
  • 10 Views
Martin Hope
Duncan
Asked: 2020-04-25 02:18:09 +0000 UTC

詹多。添加对象后的操作 (post_add)

  • 0

在 Django 中是否可以这样做,以便在添加关联模型的实例时,模型的字段会发生变化?

class Competition(models.Model):
    is_sorted = models.BooleanField()

class Gymnast(models.Model):
    parent = models.ForeignKey(Competition, related_name='gymnasts')
    name = models.CharField()

添加(删除)Gymnast实例时,需要更改关联Competition类的is_sorted字段。同时,更改 Gymnast 实例的字段(例如name)时,Competition类的is_sorted字段不会更改。 似乎有一个post_add信号,但据我了解,它是用于多对多连接的。

django
  • 1 个回答
  • 10 Views
Martin Hope
Duncan
Asked: 2020-12-15 14:33:25 +0000 UTC

如何向 django 模型添加新字段?

  • 0

我正在创建一个新的 Django 应用程序。所以我在训练。
描述竞争模式

class Competition(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, unique=True)

    def __str__(self):
        return self.title

做了迁移和所有这些。
然后我意识到应该在模型中再添加一个字段。

class Competition(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200, unique=True)
    event_place = models.CharField(max_length=200)

    def __str__(self):
        return self.title

我创建迁移 -python manage.py makemigrations
我执行迁移 -python manage.py migrate
但在表中未创建新字段。
桌子 如何向数据库中添加新字段?数据库 - SQLite。姜戈 2.0

迁移文件的内容

# Generated by Django 2.0 on 2017-12-15 06:15

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('competitions', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Competition',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=200)),
                ('slug', models.SlugField(max_length=200, unique=True)),
                ('event_place', models.CharField(max_length=200)),
            ],
    ]

结论python manage.py showmigrations

admin
 [X] 0001_initial
 [X] 0002_logentry_remove_auto_add
auth
 [X] 0001_initial
 [X] 0002_alter_permission_name_max_length
 [X] 0003_alter_user_email_max_length
 [X] 0004_alter_user_username_opts
 [X] 0005_alter_user_last_login_null
 [X] 0006_require_contenttypes_0002
 [X] 0007_alter_validators_add_error_messages
 [X] 0008_alter_user_username_max_length
 [X] 0009_alter_user_last_name_max_length
competitions
 [X] 0001_initial
 [ ] 0002_auto_20171215_0915
contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name
home
 (no migrations)
sessions
 [X] 0001_initial
python
  • 2 个回答
  • 10 Views
Martin Hope
Duncan
Asked: 2020-12-04 04:50:17 +0000 UTC

在 Kivy 应用程序界面中使用 Cyrillic 时出现 UnicodeDecodeError

  • 1

我正在尝试在界面中使用西里尔文,但应用程序无法启动。这是代码:

主文件

#  -*- coding: utf-8 -*-

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
import sys

sys.setdefaultencoding('utf-8')

class MainScreen(Screen):
    pass

class AnotherScreen(Screen):
    pass

class ScreenManagement(ScreenManager):
    pass

presentation = Builder.load_file("main.kv")

class MainApp(App):
    def build(self):
        return presentation

MainApp().run()

主文件

#  -*- coding: utf-8 -*-

ScreenManagement:
    MainScreen:
    AnotherScreen:

<MainScreen>:
    name: 'main'

    Button:
        on_release: app.root.current = 'other'
        text: 'Другой экран'
        font_size: 50

<AnotherScreen>:
    name: 'other'

    Button:
        on_release: app.root.current = 'main'
        text: 'back to the home screen'
        font_size: 50

当我运行android程序时,我得到:

[INFO ] [Kivy ] v1.9.2-dev0
[INFO ] [Python ] v3.6.2 (default, Oct 29 2017, 05:27:57)
[GCC 7.2.0]
[INFO ] [Factory ] 193 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
Traceback (most recent call last):
File "/storage/emulated/0/Download/TrafficTaxApp/TrafficTaxApp/main.py", line 19, in 
presentation = Builder.load_file("main.kv")
File "/data/data/ru.iiec.pydroid3/files/i686-linux-android/lib/python3.6/site-packages/kivy/lang/builder.py", line 290, in load_file
data = fd.read()
File "/data/data/ru.iiec.pydroid3/files/i686-linux-android/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 186: ordinal not in range(128)

在 Ubuntu 上一切都很好,没有问题。

有什么问题?

android
  • 2 个回答
  • 10 Views
Martin Hope
Duncan
Asked: 2020-11-29 21:13:51 +0000 UTC

基维。应用两页PageLayout

  • 0

如何在kivy中实现一个两页的应用程序。这样当您单击第一页上的按钮时,就会出现第二个,反之亦然。数据从第一页传输到第二页。我正在尝试通过 PageLayout 来实现。不超过..

# Custom button
<CustButton@Button>:
    font_size: 32

<TrafGridLayout>:
    id: traffictax
    display_distance: distance
    display_cost: cost
    rows: 13
    padding: 10
    spacing: 10

    PageLayout:
        border: 10

        BoxLayout:
            orientation: 'vertical'

            BoxLayout:
                Label:
                    text: 'Форма заявки'

            Label:
                text: 'Введите города'

            BoxLayout:
                Label:
                    text: 'Откуда'
                TextInput:
                    id: point_from
                    font_size: 14
                    multiline: False
                    text: ''

            BoxLayout:
                Label:
                    text: 'Куда'
                TextInput:
                    id: point_to
                    font_size: 14
                    multiline: False
                    text: ''

            # При нажатии на кнопку "Рассчитать" данные передаются в функцию "calculate" и происходит переключение на вторую страницу
            BoxLayout:
                spacing: 10
                CustButton:
                    text: "Рассчитать"
                    on_press:
                        traffictax.calculate(point_from.text, point_to.text)
                        traffictax.show_page(1)

        BoxLayout:
            orientation: 'vertical'

            Label:
                text: 'Результат'

            Label:
                text: 'Длина маршрута'

            BoxLayout:
                TextInput:
                    id: distance
                    font_size: 14
                    multiline: False

            Label:
                text: 'Стоимость'

            BoxLayout:
                TextInput:
                    id: cost
                    font_size: 14
                    multiline: False

            # При нажатии на кнопку "Назад" происходит переключение на первую страницу
            BoxLayout:
                spacing: 10
                CustButton:
                    text: "Назад к форме расчёта"
                    on_press: traffictax.show_page(0)
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