小编Nic*_*not的帖子

将OCaml字符串转换为format6

以下代码无法编译:

let x = "hello" in
Printf.printf x
Run Code Online (Sandbox Code Playgroud)

错误是:

Error: This expression has type string but an expression was expected of type
     ('a, out_channel, unit) format =
       ('a, out_channel, unit, unit, unit, unit) format6
Run Code Online (Sandbox Code Playgroud)

1)有人可以解释错误信息吗?

2)为什么字符串不能传递给printf?

ocaml

8
推荐指数
2
解决办法
1013
查看次数

如何在cython中从dict初始化结构

假设我有一个如此定义的结构:

cdef extern from "blah.h":
    struct my_struct:
        int a
        int b
Run Code Online (Sandbox Code Playgroud)

我需要能够将转换dictmy_struct,而不承担my_struct的领域的知识.换句话说,我需要进行以下转换:

def do_something(dict_arg):
    cdef my_struct s = dict_arg
    do_somthing_with_s(s)
Run Code Online (Sandbox Code Playgroud)

问题是Cython不会这样做:http://docs.cython.org/src/userguide/language_basics.html#automatic-type-conversions

当然,如果我对这个my_struct领域的名字有所了解,我可以这样做:

def do_something(dict_arg):
    cdef my_struct s = my_struct(a=dict_arg['a'], b=dict_arg['b'])
    do_somthing_with_s(s)
Run Code Online (Sandbox Code Playgroud)

这样做会使cython编译器崩溃:

def do_something(dict_arg):
    cdef my_struct s = my_struct(**dict_arg)
    do_somthing_with_s(s)
Run Code Online (Sandbox Code Playgroud)

我不知道该字段名称的原因是因为代码是自动生成的,我不想做一个丑陋的黑客来处理这种情况.

如何使用Cython从Python dict初始化结构?

struct cython

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

使用方法:包含(文本)任何带有jQuery的文本

使用jQuery,可以使用:

$(":contains(hello)")
Run Code Online (Sandbox Code Playgroud)

它将返回包含文本"hello"的任何匹配元素.

我希望能够匹配任何文本,尤其是"你好:)".

$(":contains(hello :))") // Doesn't work
$(":contains('hello :)')") // Doesn't work
$(":contains('hello :\)')") // Doesn't work
Run Code Online (Sandbox Code Playgroud)

如何使用jQuery查找包含"hello :)"的元素?

javascript jquery jquery-selectors

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

标签 统计

cython ×1

javascript ×1

jquery ×1

jquery-selectors ×1

ocaml ×1

struct ×1