小编Sco*_*nce的帖子

Python argparse:在帮助条目之间插入空白行

使用argparse时,传递--help给程序会生成帮助文本.不幸的是,它很难阅读,因为选项之间没有空行.这是一个摘录来说明:

optional arguments:
  -h, --help            show this help message and exit
  -u FILENAME, --up-sound FILENAME
                        The sound to play when the network comes up. Default:
                        "/path/to/some/sound/file.wav"
  -d FILENAME, --down-sound FILENAME
                        The sound to play when the network goes down. Default:
                        "/path/to/some/other/sound/file.wav"
  -p EXECUTABLE, --player EXECUTABLE
                        The program to use to play sounds. Default: "play"
  -s, --silent          If specified, network_monitor.py will not play any
                        sounds.
  -c, --no-clear-screen
                        If specified, screen will not be cleared (nor extra
                        blank lines added) …
Run Code Online (Sandbox Code Playgroud)

python argparse

9
推荐指数
1
解决办法
810
查看次数

OpenOffice Python宏:我在哪里可以找到有用的文档?

我正在尝试为OpenOffice Calc创建一个宏,它将切换包含用户指定值的单元格的背景颜色.由于我不知道OpenOffice Basic并且不想学习它,我想用Python编写我的宏.

麻烦的是,我找不到任何有关如何编写Python宏的有用文档.从我已经完成的阅读中看来,我无法建立一个动态环境,我可以从中检查适当的对象本身,因此我将不得不完全依赖文档.我在哪里可以学习如何编写宏?

编辑:

我已经知道" Python作为宏语言 ",但它只回答了放置Python文件的位置.它没有说明API,如何搜索和修改单元格等.

此外,没有关于XSCRIPTCONTEXTOOo显然作为全局变量提供的信息.由于我无法以交互方式运行,因此我无法真正询问该变量以了解它.

编辑2:

我发现了一些页面提供了一些信息,但它们要么非常不完整,要么假设有一个全面的UNO API预先存在的知识.到目前为止,我还没有找到任何有用的东西.我根本没有时间尝试学习整个API,因此我可以理解它的一部分 - 特别是因为我必须学习C++才能理解文档中使用的语法.

python macros openoffice-calc

7
推荐指数
1
解决办法
3372
查看次数

使此函数采用任意长度的字符串

此函数采用一串数字和一个目标整数,并打印所有可能的方法来插入运算符以达到所需的目标.在所有情况下,输出必须按顺序包含所有数字; 没有可以省略.

#!/usr/bin/env python3

def find_expressions(digits, target):
    if not (isinstance(digits, str) or isinstance(digits, list)) or not isinstance(target, int):
        raise TypeError
    if len(digits) != 5:
        raise TypeError('digits must be of length 5')
    solutions = []
    operators = ('', ' + ', ' - ', ' * ', ' / ')
    for i in operators:
        for j in operators:
            for k in operators:
                for l in operators:
                    s = digits[0] + i + digits[1] + j + digits[2] + k + digits[3] …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

makemigrations没有检测到新模型

Django 1.11.我最近将以下模块添加到myapp.models:

from django.db import models
from ordered_model.models import OrderedModel

from .songs import Song

class Service(models.Model):
    name = models.CharField(max_len=200, unique=True)
    date = models.DateField(blank=True)
    items = models.ManyToManyField(ServiceItem)

    class Meta:
        ordering = ('-date', 'name')

class ServiceItem(OrderedModel):
    item = models.ForeignKey(Song)
    song_custom_order = models.CharField(max_len=50, blank=True)
    order_with_respect_to = 'service'

    class Meta(OrderedModel.Meta):
        pass
Run Code Online (Sandbox Code Playgroud)

我在另一个模块中有其他模型(在同一目录中).当我运行时./manage.py makemigrations,脚本会在我的其他模块中找到我的更改,但不会在此模块中找到.FWIW,此模块是所有新代码,没有以前的迁移历史记录.

任何想法为什么这些变化都没有被提升?

python django django-models

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