以下代码无法编译:
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?
假设我有一个如此定义的结构:
cdef extern from "blah.h":
struct my_struct:
int a
int b
Run Code Online (Sandbox Code Playgroud)
我需要能够将转换dict成my_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初始化结构?
使用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 :)"的元素?