簡體   English   中英

MongoDB ObjectID的JSON序列化(范圍外查詢)

[英]JSON serialization of MongoDB ObjectID (ex-scope query)

我很困惑如何在其他條件之外可以使用變量temp_dict? 當我將數組保存到MongoDB時,它正在數組中的每個項目上設置ObjectId。 Json解析器不知道如何序列化ObjectId。

def read_temporary_file(filename, has_header=False):
    wb = load_workbook(filename=filename, use_iterators=True)
    ws = wb.get_active_sheet()  # ws is now an IterableWorksheet

    headers = []
    rows = []
    documents = []

    for row in ws.iter_rows():  # it brings a new method: iter_rows()
        if has_header:
            has_header = False
            for cell in row:
                headers.append(cell.internal_value)
        else:
            temp_dict = OrderedDict()
            for cell in row:
                temp_dict[cell.column] = cell.internal_value
            rows.append(temp_dict)
            documents.append(temp_dict)

    print("Saving documents to MongoDB")
    __save(documents)
    print("Printing %s" % temp_dict)
    return (headers, rows)

在Python中,整個功能就是作用域。 像您其他的條款不是新的作用域。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM