小编Sta*_*uru的帖子

包含值的排序列表:无,结果为 TypeError:“NoneType”和“str”的实例之间不支持“<”

我有包含key:value对列表的字典。如何对包含key:value对的列表进行排序(其中值为None

from operator import itemgetter
test = {"test":[{ "name" : "Nandini", "age" : 20}, { "name" : "Manjeet", "age" : 20 }, { "name" : None , "age" : 19 }] }
print(sorted(test["test"], key=itemgetter('name')) )
Run Code Online (Sandbox Code Playgroud)

结果到 TypeError: '<' not supported between instances of 'NoneType' and 'str'

输出应包括None值,如下所示:[{ "name" : None , "age" : 19 }, { "name" : "Manjeet", "age" : 20 },{ "name" : "Nandini","age" : 20}]

sorting operators python-3.x nonetype

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

如何将参数从“conftest,py”传递到测试文件(pytest)?

如何将参数传递给conftest.py文件test

测试.py

import sys,pytest


def tear_down():
    print("teardown")

def pytest_addoption(parser):
    parser.addoption("--a1", action="store", default="some_default_value", help="provide a1")
    parser.addoption("--b1", action="store", default=None, help="provide b1")
    parser.addoption("--c1", action="store", default=None, help="provide c1")


@pytest.fixture(autouse=True)
def set_up(request):
    print("set up")

    a1 = request.config.getoption("--a1")
    b1 = request.config.getoption("--b1")
    c1 = request.config.getoption("--c1")

    if not(b1) and not(c1):
        sys.exit("Both values can't be empty")

    if b1 and c1:
        sys.exit("provide either b1 or c1, not both")
Run Code Online (Sandbox Code Playgroud)

在中test.py,我需要访问所有这些参数a,b & c。我怎样才能做到这一点 ?

测试.py

import pytest

class Test1:
    def fun1(self,a,b="",c=""):
        print("task1")

    def fun2(self,a,b="",c=""): …
Run Code Online (Sandbox Code Playgroud)

pytest python-3.x conftest

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

'Cwd' 和 'qw' 在 perl 中是什么意思?

在 perl 中,我们导入/使用模块 weuse Cwd; qw作为列表/数组的表示。

但是,我在一些代码中看到它如下所述。

use Cwd qw(realpath cwd);
realpath( $0 ) =~ /(.+)\/[^\/]+$/;
require "$1/some_file.pl"
Run Code Online (Sandbox Code Playgroud)

这是什么意思 ?你能帮我理解吗?

perl

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

标签 统计

python-3.x ×2

conftest ×1

nonetype ×1

operators ×1

perl ×1

pytest ×1

sorting ×1