tailieunhanh - PROGRAMMING IN PYTHON 3 - PART 10

Tham khảo tài liệu 'programming in python 3 - part 10', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 546 Chapter 14. Introduction to Parsing object. We convert this object into a standard Python list so now we have a list containing a single item a list of our results which we assign to the items variable and that we then further process via the populate_children call. Before discussing the handling of the results we will briefly mention the error handling. If the parser fails it will raise an exception. We don t want PyParsing s exceptions to leak out to clients since we may choose to change the parser generator later on. So if an exception occurs we catch it and then raise our own exception a ValueError with the relevant details. The In the case of a successful parse of the example the items list hierar- looks like this with occurrences of object at 0x8f52acd and . similar replaced with Block for clarity 525 0 Block 2 0 Block 2 Block 0 Block The file 526 Whenever we parsed an empty block we returned 0 to the parser s results list whenever we parsed new rows we returned the number of rows and whenever we encountered a node_data we created a Block to represent it. In the case of Blocks they always have an empty child list . the children attribute is set to since at this point we don t know if the block will have children or not. So here the outer list represents the root block the 0s represent empty blocks the other integers all 2s in this case represent new rows and the s are empty child lists since none of the file s blocks contain other blocks. The example s items list pretty printed to reveal its structure and again using Block for clarity is Block Block 0 Block 2 Block 0 Block 1 0 Here we can see that the outer list representing the root block contains a block that has a child list of one block that contains its own child list and where these children are blocks with their own empty child lists new rows 2 and 1 and empty blocks 0s . One problem with the list results representation is .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.