小编lig*_*lig的帖子

简单的工具/库可视化巨大的python dict

我有一个像这样的巨大的字典结构:

my_data = {
    'key1': {
        '_': 'value1': 'aaa'
    },
    'key2': {
        '_': 'value2': 'bbb',
        'key2.1': {
            '_': 'ccc',
            'key2.1.1': {
                '_': 'ddd'
            }
        }
        'key2.2': {
            '_': 'eee',
            'key2.2.1': {
                '_': 'fff'
            }
            'key2.2.2': {
                '_': 'ggg'
            }               
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

等等.

我希望以一种树形式向用户显示它,使用GTK,TK或任何能够浏览它的东西可以折叠和扩展分支并可能搜索键和值.

可能我不需要手工开发这样的工具,并且已经有一些东西可以直观地显示这种数据?

python gtk user-interface dictionary tkinter

12
推荐指数
3
解决办法
9328
查看次数

引用计数在Python C扩展中

我正在编写我对Python的第一个C扩展,并且对我的引用计数感到困惑.这就是我想要做的.

我在for循环中填充了一个dict:

mydict = PyDict_New();

for (...)
{
    pair = PyTuple_Pack(2, PyString_FromString("some string"),
          PyString_FromString("some other string"));

    /* at this point, the refcnt for the tuple is 1, the refcnts for the
       2 string items are 2. Because according to the source, PyString_FromString
       does an INCREF, and PyTuple_Pack() does an INCREF on its items
     */

    PyDict_SetItem(mydict, PyString_FromString("some key"), pair);

    /* At this point, the key's refcnt is 2.  PyString_FromString sets it to 1 and 
       PyDict_SetItem INCREF's it. Ditto for pair since …
Run Code Online (Sandbox Code Playgroud)

c python

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

如何在mgo中取消引用dbref?

var (
    type User struct{
        Id bson.ObjectId `bson:"_id"`
        Name string
    }

type Post struct{
    Id bson.ObjectId `bson:"_id"`
    Uid string
    User User
    ref mgo.DBRef
    Title string
    }
)
Run Code Online (Sandbox Code Playgroud)

//尝试10000次插入

id := bson.NewObjectId()
user := &User{ id, "test"}
db.C("users").insert(user)

post := db.C("Post").insert(&Post{Uid: id.hex(), ref: mgo.DBRef{"ref":"users", "id": id}, Title:"test dbref"})
Run Code Online (Sandbox Code Playgroud)

//第一道这么脏-_-!

// mysql:在user.id = post.uid上加入用户,在mgo中怎么做?

posts := new([]User)
db.C("posts").Find(nil).All(posts)

ids := []bson.ObjectId
for _, p := range posts{
  ids = append(ids, p.Uid)
}

users := make([]User, len(ids))
db.C("users").Find(bson.M{"_id": {"$in": ids}}).All(users)

//and then set …
Run Code Online (Sandbox Code Playgroud)

go mgo

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

如何在Dart中处理套接字断开连接?

我在服务器上使用Dart 1.8.5.我想实现侦听传入连接的TCP Socket Server,将一些数据发送到每个客户端,并在客户端断开连接时停止生成数据.

这是示例代码

void main() {
  ServerSocket.bind(
      InternetAddress.ANY_IP_V4,
      9000).then((ServerSocket server) {
    runZoned(() {
      server.listen(handleClient);
    }, onError: (e) {
      print('Server error: $e');
    });
  });
}

void handleClient(Socket client) {
  client.done.then((_) {
    print('Stop sending');
  });
  print('Send data');
}
Run Code Online (Sandbox Code Playgroud)

此代码接受连接并打印"发送数据".但即使客户离开,也永远不会打印"停止发送".

问题是:如何在侦听器中捕获客户端断开连接?

sockets dart

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

从<th>标签获取价值

我怎样才能从中读取值

<th class="class_name"> Sample Text </th>
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我使用python从上面的HTML代码中获取字符串"Sample Text".

谢谢.

html python parsing

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

标签 统计

python ×3

c ×1

dart ×1

dictionary ×1

go ×1

gtk ×1

html ×1

mgo ×1

parsing ×1

sockets ×1

tkinter ×1

user-interface ×1