python类concat()的实例源码

utils.py 文件源码 项目:pudzu 作者: Udzu 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def number_of_args(fn):
    """Return the number of positional arguments for a function, or None if the number is variable.
    Looks inside any decorated functions."""
    try:
        if hasattr(fn, '__wrapped__'):
            return number_of_args(fn.__wrapped__)
        if any(p.kind == p.VAR_POSITIONAL for p in signature(fn).parameters.values()):
            return None
        else:
            return sum(p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD) for p in signature(fn).parameters.values())
    except ValueError:
        # signatures don't work for built-in operators, so check for a few explicitly
        UNARY_OPS = [len, op.not_, op.truth, op.abs, op.index, op.inv, op.invert, op.neg, op.pos]
        BINARY_OPS = [op.lt, op.le, op.gt, op.ge, op.eq, op.ne, op.is_, op.is_not, op.add, op.and_, op.floordiv, op.lshift, op.mod, op.mul, op.or_, op.pow, op.rshift, op.sub, op.truediv, op.xor, op.concat, op.contains, op.countOf, op.delitem, op.getitem, op.indexOf]
        TERNARY_OPS = [op.setitem]
        if fn in UNARY_OPS:
            return 1
        elif fn in BINARY_OPS:
            return 2
        elif fn in TERNARY_OPS:
            return 3
        else:
            raise NotImplementedError("Bult-in operator {} not supported".format(fn))
spreadsheet_formula.py 文件源码 项目:transformer 作者: zapier 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def get_default_operators():
    """ generate a mapping of default operators allowed for evaluation """
    return {
        'u-': Func(1, operator.neg),             # unary negation
        'u%': Func(1, lambda a: a / Decimal(100)), # unary percentage
        '&': Func(2, operator.concat),
        '^': Func(2, operator.pow),
        '+': Func(2, op_add),
        '-': Func(2, operator.sub),
        '/': Func(2, operator.truediv),
        '*': Func(2, operator.mul),
        '=': Func(2, operator.eq),
        '<>': Func(2, lambda a, b: not operator.eq(a, b)),
        '>': Func(2, operator.gt),
        '<': Func(2, operator.lt),
        '>=': Func(2, operator.ge),
        '<=': Func(2, operator.le),
    }
utils.py 文件源码 项目:triage 作者: dssg 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def feature_list(feature_dictionary):
    """Convert a feature dictionary to a sorted list.

    Args: feature_dictionary (dict)

    Returns: sorted list of feature names

    """
    return sorted(
        functools.reduce(
            operator.concat,
            (feature_dictionary[key] for key in feature_dictionary.keys())
        )
    )
prelude.py 文件源码 项目:concepts 作者: sminez 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def conj(head, tail):
    '''
    Prepend an element to a collection, returning a new copy
    Exact behaviour will differ depending on the collection
    '''
    tail_type = type(tail)
    return op.concat(tail_type([head]), tail)
test_operator.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29)
test_operator.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29)
test_operator.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29)
test_operator.py 文件源码 项目:web_ctp 作者: molebot 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29)
toolchain_gcc.py 文件源码 项目:beremiz 作者: nucleron 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def concat_deps(self, bn):
        # read source
        src = open(os.path.join(self.buildpath, bn), "r").read()
        # update direct dependencies
        deps = []
        self.append_cfile_deps(src, deps)
        # recurse through deps
        # TODO detect cicular deps.
        return reduce(operator.concat, map(self.concat_deps, deps), src)
toolchain_makefile.py 文件源码 项目:beremiz 作者: nucleron 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def concat_deps(self, bn):
        # read source
        src = open(os.path.join(self.buildpath, bn), "r").read()
        # update direct dependencies
        deps = []
        for l in src.splitlines():
            res = includes_re.match(l)
            if res is not None:
                depfn = res.groups()[0]
                if os.path.exists(os.path.join(self.buildpath, depfn)):
                    # print bn + " depends on "+depfn
                    deps.append(depfn)
        # recurse through deps
        # TODO detect cicular deps.
        return reduce(operator.concat, map(self.concat_deps, deps), src)
test_operator.py 文件源码 项目:pefile.pypy 作者: cloudtracer 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29)
linelength.py 文件源码 项目:pipenv 作者: pypa 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _fixed_table(table_element):
    """
    Returns a new TableElement.
    """
    assert isinstance(table_element, TableElement)
    lines = tuple(common.lines(table_element.sub_elements))
    fixed_lines = tuple(_fixed_line(l) if _line_length(l) > MAXIMUM_LINE_LENGTH else l for l in lines)
    return TableElement(sub_elements=tuple(reduce(operator.concat, fixed_lines)))
deindentanonymoustable.py 文件源码 项目:pipenv 作者: pypa 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def _unindent_table(table_element):
    table_lines = tuple(common.lines(table_element.sub_elements))
    unindented_lines = tuple(tuple(dropwhile(lambda e: isinstance(e, WhitespaceElement), line)) for line in table_lines)
    return TableElement(reduce(operator.concat, unindented_lines))
tableentrysort.py 文件源码 项目:pipenv 作者: pypa 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _sorted_table(table):
    """
    Returns another TableElement where the table entries are sorted lexicographically by key.
    """
    assert isinstance(table, TableElement)

    # Discarding TokenElements with no tokens in them
    table_elements = common.non_empty_elements(table.sub_elements)
    lines = tuple(common.lines(table_elements))
    sorted_lines = sorted(lines, key=_line_key)
    sorted_elements = reduce(operator.concat, sorted_lines)

    return TableElement(sorted_elements)
test_operator.py 文件源码 项目:ndk-python 作者: gittor 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_concat(self):
        self.assertRaises(TypeError, operator.concat)
        self.assertRaises(TypeError, operator.concat, None, None)
        self.assertTrue(operator.concat('py', 'thon') == 'python')
        self.assertTrue(operator.concat([1, 2], [3, 4]) == [1, 2, 3, 4])
        self.assertTrue(operator.concat(Seq1([5, 6]), Seq1([7])) == [5, 6, 7])
        self.assertTrue(operator.concat(Seq2([5, 6]), Seq2([7])) == [5, 6, 7])
        self.assertRaises(TypeError, operator.concat, 13, 29)
misc.py 文件源码 项目:pyshtrih 作者: oleg-golovanov 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def bytearray_concat(*args):
    """
    ??????? ???????????????? ?????????? bytearray ? ????.
    """

    return bytearray_cast(reduce(operator.concat, args))
fun.py 文件源码 项目:pisi 作者: examachine 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def concat(l):
    '''concatenate a list of lists'''
    return reduce( operator.concat, l )
fun.py 文件源码 项目:pisi 作者: examachine 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def multisplit(str, chars):
    """ split str with any of chars"""
    l = [str]
    for c in chars:
        l = concat(map(lambda x:x.split(c), l))
    return l


问题


面经


文章

微信
公众号

扫码关注公众号