Python新手-运算符//

时间:2019-01-10 19:07:25

标签: python

我找到了一些应该起作用的代码,但是没有。.我在做什么错/丢失了?

来源:How to find table like structure in image

def find_table_in_boxes(boxes, cell_threshold=10, min_columns=2):
    for box in boxes:
        (x, y, w, h) = box
        print(box)
        col_key = x // cell_threshold

if __name__ == '__main__':
    text_boxes = [
        {
            'x': 123,
            'y': 512,
            'w': 100,
            'h': 150
        },
        {
            'x': 500,
            'y': 512,
            'w': 100,
            'h': 150
        }
    ]
    cells = find_table_in_boxes(text_boxes)

错误

# python test.py
{'x': 123, 'w': 100, 'y': 512, 'h': 150}
Traceback (most recent call last):
  File "test.py", line 22, in <module>
    cells = find_table_in_boxes(text_boxes)
  File "test.py", line 5, in find_table_in_boxes
    col_key = x // cell_threshold
TypeError: unsupported operand type(s) for //: 'str' and 'int'

1 个答案:

答案 0 :(得分:8)

它告诉您T是一个字符串。它来自class Action<T extends Promise<string> | Observable<string> | ReadableStream<string>> { dispatcher: (x: string) => T; constructor(dist: (x: string) => T) { this.dispatcher = dist } f = (s: string) => this.dispatcher('hello' + s); } // note that x is type string in this: const promiseDispatcher = (x: string) => Promise.resolve(x) const a = new Action(promiseDispatcher); a.f("random string").then((s: string) => { // ... }) ,来自apply(a, 2, function(x) paste('p', parent.frame()$i[], ': ', x, sep='')) 。您不能使用以下命令解包字典值:

Session::put('name','value')

尝试以下方法:

x

另一个选择是:

boxes