小编icy*_*ndy的帖子

python按值列出的json排序列表

我有一个由JSON组成的文件,每行一行,并希望通过update_time对文件进行排序.

示例JSON文件:

{ "page": { "url": "url1", "update_time": "1415387875"}, "other_key": {} }
{ "page": { "url": "url2", "update_time": "1415381963"}, "other_key": {} }
{ "page": { "url": "url3", "update_time": "1415384938"}, "other_key": {} }
Run Code Online (Sandbox Code Playgroud)

想要输出:

{ "page": { "url": "url1", "update_time": "1415387875"}, "other_key": {} }
{ "page": { "url": "url3", "update_time": "1415384938"}, "other_key": {} }
{ "page": { "url": "url2", "update_time": "1415381963"}, "other_key": {} }
Run Code Online (Sandbox Code Playgroud)

我的代码:

#!/bin/env python
#coding: utf8

import sys
import os
import json
import operator

#load json from file …
Run Code Online (Sandbox Code Playgroud)

python lambda json sorted

25
推荐指数
3
解决办法
6万
查看次数

vim yaml 文件注释行时缩进错误

我已经尝试过autocmd 方式,但对我不起作用。

  1. 一行注释i,缩进错误。

i行首,然后按##光标自动缩进。

一行评论与我

  1. 一行注释I,向右缩进。

I在行首按下,光标自动缩进;然后按#

与我的一行评论

  1. 块注释用Ctrl+ v,后跟Shift+ i,后跟Esc,缩进错误。

块评论

- - - - - - - - - - -编辑 - - - - - - - - - - - -

  1. 将光标放在块注释上-

第一块和第二块的行为不同。

在此输入图像描述

vim yaml

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


ctypes如何将字符串从python传递到c ++函数,以及如何将字符串从c ++函数返回到python

我想从python调用一个c ++函数,这个c ++函数将char*作为参数,并返回字符串.以下是我的代码.

wrapper.cpp

#include <Python.h>
#include <string>
#include <iostream>

using namespace std;

extern "C"
string return_string(char* name){
    cout<<strlen(name)<<endl;
    cout<<name<<endl;
    string s = "hello ";
    s += name;
    return s;
}
Run Code Online (Sandbox Code Playgroud)

将wrapper.cpp编译为example.so

g++ -fPIC wrapper.cpp -o example.so -shared -I/usr/include/python2.7/
Run Code Online (Sandbox Code Playgroud)

wrapper.py

import os
from ctypes import *

lib = cdll.LoadLibrary('./example.so')
lib.return_string.restype = c_char_p
lib.return_string.argtypes = [c_char_p]
name = create_string_buffer("Tom")
s = lib.return_string(name);
print s
print name
Run Code Online (Sandbox Code Playgroud)

这是我的输出

18
??H?L?l???A???
1
<ctypes.c_char_Array_4 object at 0x7f5f480be710>
Run Code Online (Sandbox Code Playgroud)

如何使其工作?

c++ python string ctypes

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

依赖解析网页上的树可视化

下面是依赖解析树的示例.

依赖解析树

我想在html网页上将其可视化,任何人都可以向我展示一些示例或方向吗?我熟悉C/C++,Python,但不熟悉html/javascript.

非常感谢!

html5 dependencies parsing visualization

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