Làm cách nào để tạo danh sách nhóm trong python?

To help you organize groups of things, docassemble offers three data structures. danh sách, từ điển và bộ. These mirror the list, , and data types that exist in Python

Lists in Python

A “list” is a group that has a defined order. Elements are numbered with an index that starts from zero. In Python, if a list is defined as

fruit = ['apple', 'orange', 'pear']

then mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0 will return mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.1, mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.2 will return mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.3, and mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.4 will return mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.5. You can try this out in a Python interpreter

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'

Adding a new element to the list is called “appending” to the list

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']

The is a built-in Python function that arranges a list in order

In docassemble, lists are typically defined as special objects of type , which behave much like Python lists

Dictionaries in Python

A “dictionary” is a group of key/value pairs. By analogy with an actual dictionary, the “key” represents the word and the “value” represents the definition. In Python, if a dictionary is defined as

feet = {'dog': 4, 'human': 2, 'bird': 2}

then mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.8 will return mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.9, question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any0 will return question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any1, and question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any2 will return question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any1. The keys are question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any4, question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any5, and question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any6, and the values are mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.9, question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any1, and question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any1, respectively

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet

The keys of a dictionary are unique. Setting >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'00 will add a new entry to the above dictionary, whereas setting >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'01 will change the existing entry for question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any4. The items in a dictionary are “unordered,” so if you want to loop through them in a particular order, you will need to take special steps to ensure the items appear in that order, such as keeping a separate list of the keys in your desired order

In docassemble, dictionaries are typically objects of type , which behave much like s

Sets in Python

A “set” is a group of unique items with no order. There is no index or key that allows you to refer to a particular item; an item is either in the set or is not. (A set in Python behaves much like a set in mathematical set theory. ) In Python, a set can be defined with a statement like >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'04. Adding a new item to the set is called “adding,” not “appending. ” For example. >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'05. If you add an item to a set when the item is already in the set, this will have no effect on the set

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])

In docassemble, sets are typically objects of type , which behave much like s

When you want to gather information from the user into a list, dictionary, or set, you should use the objects , , and (or subtypes thereof) instead of Python’s basic list, , and data types. These objects have special attributes that help interviews find the right blocks to use to populate the items of the group

If you want to, you can use Python’s basic list, , and data types in your interviews; nothing will stop you – but there are no special features to help you gather information into these data structures using or

The following interview populates a list of fruits

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another

The variable >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 is defined as a object

objects: - fruit: DAList

Một khối giống như một khối, ngoại trừ việc nó thực hiện một mục đích đặc biệt là định nghĩa các đối tượng docassemble. Nếu docassemble cần biết định nghĩa của biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12, nó sẽ sử dụng khối này và khởi tạo >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 như một. (Nếu bạn quen thuộc với Python, bạn có thể coi đây là một khối chạy >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'19 trong đó mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7 là một lớp Python. )

Khối tiếp theo chứa điểm kết thúc của cuộc phỏng vấn, một màn hình cho biết có bao nhiêu loại trái cây trong danh sách và liệt kê chúng

mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.

Vì đây là , docassemble cố gắng hỏi nó. Tuy nhiên, nó gặp phải >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'23, trả về số mục trong danh sách (e. g. , “hai”, “ba”, v.v. ). Nhưng để biết có bao nhiêu mục trong danh sách, docassemble cần hỏi người dùng những mục đó là gì. Vì vậy, việc tham chiếu đến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'23 sẽ ngầm kích hoạt quá trình đặt câu hỏi để thu thập danh sách. Tham chiếu đến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'25 cũng sẽ kích hoạt quy trình tương tự, nhưng docassemble sẽ gặp >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'23 trước

Đằng sau hậu trường, khi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'23 được chạy và docassemble cần thu thập danh sách, nó sẽ chạy >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'28, một thuật toán thu thập. Phương pháp điều phối quá trình thu thập bằng cách kích hoạt việc tìm kiếm các biến cần thiết để thu thập danh sách

Nhiều thứ khác ngoài >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'30 sẽ ngầm kích hoạt việc thu thập danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12. Nếu bạn lặp lại trên >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 hoặc chạy một phương thức sử dụng các mục trong danh sách, điều này sẽ kích hoạt việc thu thập. Ưu điểm của kích hoạt ngầm định là mã của bạn có thể ngắn gọn và cuộc phỏng vấn của bạn sẽ được cân nhắc kỹ lưỡng về việc có nên đặt câu hỏi để thu thập danh sách hay không; . Nếu bạn muốn nói rõ ràng về thời điểm các câu hỏi thu thập danh sách được hỏi, bạn có thể tự mình gọi cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'28, có lẽ trong một

Thuật toán thu thập hoạt động giống như một luật sư thẩm vấn nhân chứng

"Bạn có con không?"

“Có,” nhân chứng trả lời

“Đứa con đầu lòng của bạn tên là gì?”

“James. ”

"Ngoài James, bạn có con nào khác không?"

"Đúng"

“Đứa con thứ hai của bạn tên là gì?”

“Charlotte. ”

“Ngoài James và Charlotte, anh còn đứa con nào khác không?”

"Không"

Phương pháp kích hoạt những câu hỏi này bằng cách tìm kiếm các giá trị của các biến khác nhau

  • >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'37. có nên có bất kỳ mục nào trong danh sách không?
  • >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'38. tên của loại trái cây thứ 39 trong danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'
  • >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40. có trái cây nào vẫn cần được thêm vào không?

Đầu tiên, người phỏng vấn sẽ muốn biết liệu có bất kỳ mục nào trong danh sách hay không. Nó sẽ tìm kiếm một định nghĩa cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'37. Do đó, nó sẽ đặt câu hỏi, “Có loại trái cây nào bạn muốn thêm vào danh sách không?”

question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any

Nếu câu trả lời cho điều này là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, cuộc phỏng vấn sẽ tìm kiếm một định nghĩa cho mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0 để thu thập yếu tố đầu tiên. Vì vậy, nó sẽ đặt ra câu hỏi “Nên thêm loại trái cây nào vào danh sách?”

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'0

Điều này sử dụng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39. Biến đặc biệt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 có nghĩa là câu hỏi được khái quát hóa; . ). quy trình thu thập của docassemble sẽ tự động đảm nhiệm việc đặt biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 thành giá trị phù hợp trước khi sử dụng giá trị này

Giả sử người dùng nhập “táo. ”

Bây giờ docassemble biết mục đầu tiên trong danh sách, nhưng nó không biết liệu danh sách đã đầy chưa. Do đó, nó sẽ tìm kiếm một định nghĩa cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40. Nó sẽ đặt câu hỏi “Cho đến nay, các loại trái cây bao gồm táo. Có cái nào khác không?”

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'1

Nếu câu trả lời cho điều này là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, cuộc phỏng vấn sẽ tìm kiếm định nghĩa về mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.2 để thu thập mục thứ hai trong danh sách. Nó sẽ hỏi lại, “Trái cây nào nên được thêm vào danh sách?” . ”

Sau đó, cuộc phỏng vấn sẽ lại tìm kiếm định nghĩa của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40. Lần này, nếu câu trả lời là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58, thì phương thức >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'28 sẽ trả về mà không hỏi bất kỳ câu hỏi nào và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'23 sẽ trả lời với số mục trong >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 (trong trường hợp này là 2). Khi sau này docassemble gặp >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'62, nó sẽ cố gắng rút gọn biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 thành văn bản. Vì người phỏng vấn biết rằng không còn yếu tố nào trong danh sách nên không cần đặt thêm câu hỏi nào nữa. >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'25 sẽ dẫn đến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'65

Lưu ý rằng biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 là một biến đặc biệt trong docassemble. Khi cuộc phỏng vấn tìm kiếm một định nghĩa cho mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0, trước tiên cuộc phỏng vấn sẽ tìm kiếm một câu hỏi đưa ra định nghĩa về mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0. Nếu không tìm thấy, nó sẽ thực hiện một cách tiếp cận tổng quát hơn và tìm câu hỏi đưa ra để xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'38. Câu hỏi cung cấp để xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'38 sẽ được sử dụng lại nhiều lần nếu cần

Vì biến chỉ mục >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 là một biến đặc biệt, bạn không bao giờ nên tự đặt nó;

Bạn cũng không bao giờ nên sử dụng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 trong hoặc khối. Việc sử dụng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 được dành riêng cho các khối docassemble gọi khi nó đang tìm cách xác định một biến có chỉ mục, chẳng hạn như mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.4 và không có khối nào xác định rõ ràng mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.4. Nếu bạn sử dụng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 trong một khối, bạn sẽ gặp lỗi rằng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 không được xác định hoặc nếu >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 được xác định, nó có thể được định nghĩa là một giá trị không có ý nghĩa đối với ngữ cảnh mà bạn đang sử dụng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39

Để biết thêm thông tin về cách sử dụng các biến như >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39, hãy xem các phần về và

Tùy chỉnh cách thu thập thông tin

Cách docassemble đặt câu hỏi để điền vào danh sách như >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 có thể được tùy chỉnh bằng cách đặt các thuộc tính của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12. Ví dụ: có lẽ bạn muốn các câu hỏi trong cuộc phỏng vấn diễn ra như thế này

  1. Có bao nhiêu quả?
  2. Tên của quả đầu tiên là gì?
  3. Tên của quả thứ hai là gì?
  4. vân vân

Để đặt câu hỏi theo cách này, hãy đặt thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'86 của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42. Cũng bao gồm một câu hỏi hỏi "Có bao nhiêu loại trái cây?" . (Thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'90 là thuộc tính đặc biệt, giống như >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91. )

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'2

Ví dụ này sử dụng the để khởi tạo thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'93 của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12. Một cách khác để khởi tạo thuộc tính là sử dụng một khối khi bắt đầu cuộc phỏng vấn

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'3

Nói chung, tốt nhất là sử dụng

Bạn có thể tránh câu hỏi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'97 bằng cách đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'98 thành một giá trị

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'4

Thu thập danh sách các đối tượng

Các ví dụ trên đã tập hợp các biến đơn giản (e. g. , mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.1, mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.3) thành một danh sách. Bạn cũng có thể tập hợp các đối tượng thành một danh sách. Bạn có thể thực hiện việc này bằng cách đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01 của một (hoặc loại phụ của nó) thành loại đối tượng mà bạn muốn các mục trong danh sách là

Trong ví dụ này, chúng tôi tập hợp các đối tượng thành một bằng cách đặt thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']03

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'5

Có một số loại danh sách có một ____8_______01 theo mặc định. Ví dụ: các danh sách có >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01 của

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'6

Trong quá trình thu thập, docassemble chỉ thu thập các thuộc tính cần thiết để hiển thị từng đối tượng dưới dạng văn bản (theo mặc định). Vì vậy, nếu bạn làm

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'7

sau đó danh sách sẽ bao gồm s và docassemble sẽ thu thập >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']12 cho mỗi mục trong danh sách. Điều này là do cách mà đối tượng hoạt động. nếu >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']14 là một , thì biểu diễn văn bản của nó (e. g. , bao gồm >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']16 trong mẫu Mako hoặc gọi ___8_______17 bằng mã Python) sẽ chạy ____8_______18, ở mức tối thiểu, yêu cầu định nghĩa cho ____8____19. (Xem tài liệu để biết thêm chi tiết. ) Các loại đối tượng khác hoạt động khác. Ví dụ: nếu >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']14 là một , bao gồm >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']16 trong mẫu Mako sẽ dẫn đến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']24, điều này phụ thuộc vào các thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']25, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']26 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']27. Nếu bạn sử dụng một cách đơn giản như >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']29, thì sẽ không có câu hỏi nào được đặt ra; . Do đó, việc gọi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']17 đơn giản sẽ chỉ trả về một tên dựa trên tên biến;

Nếu cuộc phỏng vấn của bạn có một danh sách các s và sử dụng các thuộc tính của s bên cạnh tên, docassemble cuối cùng sẽ thu thập các thuộc tính bổ sung đó, nhưng nó sẽ hỏi tên trước và chỉ khi hoàn tất việc hỏi tên của từng cá nhân trong danh sách . Đây là một cuộc phỏng vấn làm điều này

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'8

Thứ tự các câu hỏi là

  1. Tên của người bạn đầu tiên của bạn là gì?
  2. Bạn có người bạn nào khác không?
  3. Tên của người bạn thứ hai của bạn là gì?
  4. Bạn có người bạn nào khác không?
  5. What is Fred’s favorite animal?
  6. What is Fred’s birthdate?
  7. What is Sally’s favorite animal?
  8. Ngày sinh của Sally là gì?

If you would prefer that all of the questions about each individual be asked together, you can use the >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']35 attribute to tell docassemble that an item is not completely gathered until a particular attribute of that item is defined. Sau đó, bạn có thể viết một định nghĩa thuộc tính này. Bạn có thể sử dụng điều này để đảm bảo rằng tất cả các câu hỏi bạn muốn được hỏi đều được hỏi trong quá trình thu thập

Trong ví dụ trên, chúng ta có thể thực hiện điều này bằng cách thực hiện >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']38. Sau đó, chúng tôi bao gồm một khối >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'11 đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']40. Điều này cho docassemble biết rằng một mục >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']41 không được thu thập đầy đủ cho đến khi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']42 được xác định. Do đó, trước khi docassemble chuyển sang mục tiếp theo trong danh sách, nó sẽ chạy mục này cho đến khi hoàn thành. Điều này sẽ khiến các thuộc tính khác của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']41 được xác định, bao gồm >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']46 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']47. Đây là những gì cuộc phỏng vấn sửa đổi trông giống như

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'9

Bây giờ thứ tự các câu hỏi là

  1. Tên của người bạn đầu tiên của bạn là gì?
  2. What is Fred’s birthdate?
  3. What is Fred’s favorite animal?
  4. Bạn có người bạn nào khác không?
  5. Tên của người bạn thứ hai của bạn là gì?
  6. Ngày sinh của Sally là gì?
  7. What is Sally’s favorite animal?
  8. Bạn có người bạn nào khác không?

Bạn có thể sử dụng bất kỳ thuộc tính nào bạn muốn làm >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']48. Định nghĩa một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']48 đơn giản có nghĩa là thay vì đảm bảo rằng một mục trong danh sách có thể hiển thị được (i. e. , thu thập tên của một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']11), docassemble sẽ tìm kiếm định nghĩa của thuộc tính được chỉ ra bởi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']48. Nếu >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']46 là yếu tố duy nhất chúng tôi muốn xác định trong quá trình thu thập, chúng tôi có thể đã viết >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']53 và bỏ qua toàn bộ

Bạn cũng có thể đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']48 thành danh sách tên thuộc tính. Trong trường hợp này, mặt hàng sẽ được coi là đầy đủ khi nó có định nghĩa cho từng thuộc tính trong danh sách các thuộc tính

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']0

Khi bạn viết các định nghĩa lớp của riêng mình, bạn có thể đặt một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']48 mặc định không thực sự là một thuộc tính, mà là một phương thức hoạt động như một thuộc tính

Trong ví dụ sau, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']57 là danh sách của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']58, trong đó >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']58 được coi là "hoàn thành" cho mục đích thu thập tự động khi các thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']60, ________8__61 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']62 đã được xác định

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']1

Đây là một cuộc phỏng vấn sử dụng định nghĩa lớp này

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']2

Thu thập danh sách trong danh sách

Dưới đây là một ví dụ về tập hợp danh sách lồng nhau (danh sách trong danh sách trong danh sách)

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']3

Khối đầu tiên xác định các đối tượng chúng ta sẽ sử dụng

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']4

(Lưu ý rằng ngắt dòng ở đây không có ý nghĩa đối với cú pháp; Python cho phép bạn sử dụng ngắt dòng trong ngữ cảnh này vì lý do thẩm mỹ. )

Danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63 sẽ là danh sách các đối tượng thuộc loại. Chúng tôi giả định rằng có ít nhất một cá nhân trong danh sách, vì vậy chúng tôi đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']65. Vì chúng tôi muốn thu thập thêm thông tin về từng cá nhân trong danh sách chứ không chỉ đơn giản là tên của cá nhân đó (biểu diễn bằng văn bản của một ), chúng tôi đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']67 để chỉ ra rằng một cá nhân chưa "đầy đủ" cho đến khi thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']68 được xác định

Ở đây chúng tôi cũng khẳng định rằng thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']69 cho bất kỳ người nào trong danh sách những người (>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']70) là một danh sách gồm s, mỗi danh sách sẽ "đầy đủ" khi thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']68 được xác định. Biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 ở đây là một biến đặc biệt do docassemble thiết lập trong quá trình thu thập danh sách. (Bạn không bao giờ nên cố gắng tự đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39. ) Nếu docassemble muốn định nghĩa của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']75, nó sẽ đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']76 và sau đó xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']75 bằng cách chạy dòng thứ hai trong khối

Khối tiếp theo xác định ý nghĩa của việc một mục trong danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63 là “hoàn thành. ”

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']5

Điều này nói rằng một điều đã cho trong danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63 (>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83) là “đầy đủ” khi tên của người đó được xác định, khi chúng tôi thu thập danh sách những người bị dị ứng và khi chúng tôi thu thập danh sách con cái của họ

Chúng ta đã thấy khối xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']70 cho bất kỳ >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 nào. Sau này chúng ta sẽ thấy khối xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']86

Khi docassemble muốn thực hiện một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']87 “hoàn thành”, nó sẽ đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']76 và sau đó chạy khối mã Python này. Nó sẽ tiếp tục chạy khối này cho đến khi nhận được câu trả lời mà nó cần. Đầu tiên nó sẽ hỏi tên của người đó, sau đó nó sẽ trải qua quy trình thu thập danh sách để thu thập các dị ứng, sau đó trải qua quy trình thu thập danh sách để thu thập trẻ em và khi không còn trẻ nào để thu thập, nó sẽ xác định . Sau đó, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83 sẽ “đầy đủ” và docassemble sẽ tiếp tục thu thập danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63

Khối tiếp theo xác định ý nghĩa của việc một đứa trẻ của một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83 đã cho là hoàn thành. Nó tương tự như khối trước, ngoại trừ cuộc phỏng vấn không hỏi về con cái của một đứa trẻ

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']6

Trong khi docassemble đang chạy >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']94, nó sẽ đặt câu hỏi để thu thập các mục trong >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']70 và để hoàn thành từng mục, chẳng hạn như >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']96 (đối với đứa con thứ hai của người thứ nhất). ” Vì thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']69 được xác định bằng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']67, nên docassemble sẽ cố gắng làm cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']96 “đầy đủ” bằng cách tìm kiếm định nghĩa của feet = {'dog': 4, 'human': 2, 'bird': 2}00. Không có khối nào trong cuộc phỏng vấn đề nghị xác định cụ thể feet = {'dog': 4, 'human': 2, 'bird': 2}00, nhưng các đề xuất ở trên để xác định feet = {'dog': 4, 'human': 2, 'bird': 2}03 cho bất kỳ tùy ý nào đối với >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 và feet = {'dog': 4, 'human': 2, 'bird': 2}05. Vì vậy, docassemble sẽ đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']76 và feet = {'dog': 4, 'human': 2, 'bird': 2}07, sau đó thử chạy cái này. Mã Python trong khối này sẽ kích hoạt tất cả các câu hỏi cần thiết để làm cho đối tượng con “hoàn thành. ”

Điều rất quan trọng là mã trong phần này nằm trong một khối riêng biệt với phần trước. Mỗi đại diện cho một tuyên bố riêng của sự thật. Câu đầu tiên cho biết cần phải làm gì để hoàn thành việc đặt câu hỏi về một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83, và câu thứ hai cho biết cần phải làm gì để hoàn thành việc đặt câu hỏi về một trong những đứa con của người đó

Nếu bạn cố gắng hợp nhất mã này với mã từ khối trước đó, thì bạn có thể gặp lỗi về biến feet = {'dog': 4, 'human': 2, 'bird': 2}05 không được xác định. Nếu docassemble đang tìm cách xác định một thuộc tính của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83, thì nó sẽ xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 và sau đó chạy khối cung cấp để xác định thuộc tính của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83. Nhưng nếu docassemble, trong quá trình chạy block định nghĩa thuộc tính của biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83, gặp biến feet = {'dog': 4, 'human': 2, 'bird': 2}05, nó sẽ không biết phải làm gì với biến đó;

Mặc dù Python là một ngôn ngữ “thủ tục”, nhưng cách hoạt động của docassemble lại mang tính “khai báo” hơn. ” Trong hầu hết các trường hợp, các khối >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'11 của bạn phải là các khai báo độc lập về cách xác định một biến đơn lẻ, ngay cả khi chúng khiến các biến khác được xác định như một tác dụng phụ. Trong ví dụ này, các biến đơn đó là feet = {'dog': 4, 'human': 2, 'bird': 2}24 và feet = {'dog': 4, 'human': 2, 'bird': 2}03. Các khối xác định các biến này sẽ được sử dụng nhiều lần trong cuộc phỏng vấn của bạn với mục đích cụ thể là xác định feet = {'dog': 4, 'human': 2, 'bird': 2}24 hoặc feet = {'dog': 4, 'human': 2, 'bird': 2}03

Khối tiếp theo có thể tái sử dụng

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']7

Điều này sẽ được sử dụng cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']87, feet = {'dog': 4, 'human': 2, 'bird': 2}31 và bất kỳ >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83 nào khác trong danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63. Nếu docassemble muốn biết feet = {'dog': 4, 'human': 2, 'bird': 2}34, nó sẽ đặt feet = {'dog': 4, 'human': 2, 'bird': 2}35 và sau đó hỏi điều này

Khối tiếp theo được sử dụng bất cứ khi nào docassemble muốn biết liệu có thêm mục nào được thêm vào danh sách hay không

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']8

Phương thức của lớp sẽ hủy xác định thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91 sau khi mỗi mục được thu thập, sau đó tìm kiếm lại định nghĩa của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91 để tìm hiểu xem có cần thu thập thêm mục nào không

Khối tiếp theo hỏi liệu một người trong danh sách >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63 có con không

>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']9

Đây là câu đầu tiên sẽ được hỏi khi docassemble chạy >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']94

Phần tiếp theo minh họa việc sử dụng hai biến chỉ số

feet = {'dog': 4, 'human': 2, 'bird': 2}0

Việc sử dụng các biến chỉ số >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 và feet = {'dog': 4, 'human': 2, 'bird': 2}05 có nghĩa là nếu docassemble muốn tìm một định nghĩa cho feet = {'dog': 4, 'human': 2, 'bird': 2}47, nó sẽ đặt feet = {'dog': 4, 'human': 2, 'bird': 2}35, đặt feet = {'dog': 4, 'human': 2, 'bird': 2}49, rồi đặt câu hỏi này

Nếu bạn muốn đặt câu hỏi theo cách khác cho người đầu tiên trong danh sách, bạn có thể bao gồm khối sau

feet = {'dog': 4, 'human': 2, 'bird': 2}1

Ở đây, biến chỉ số >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 được sử dụng thay vì feet = {'dog': 4, 'human': 2, 'bird': 2}05. docassemble sẽ chỉ hỏi điều này nếu biến mà nó tìm bắt đầu bằng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']75. Nếu docassemble đang tìm cách xác định feet = {'dog': 4, 'human': 2, 'bird': 2}54, thì nó sẽ bỏ qua điều này, bởi vì feet = {'dog': 4, 'human': 2, 'bird': 2}56 không tổng quát hóa thành feet = {'dog': 4, 'human': 2, 'bird': 2}54

Tương tự như vậy, nếu bạn muốn đặt câu hỏi theo cách khác cho đứa trẻ đầu tiên, bạn có thể bao gồm

feet = {'dog': 4, 'human': 2, 'bird': 2}2

Câu hỏi này cung cấp để xác định feet = {'dog': 4, 'human': 2, 'bird': 2}58 cho bất kỳ >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39

Bạn sẽ không bao giờ có khối đề cập đến feet = {'dog': 4, 'human': 2, 'bird': 2}05 mà không đề cập đến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39, và bạn sẽ không bao giờ có khối đề cập đến feet = {'dog': 4, 'human': 2, 'bird': 2}62 mà không đề cập đến feet = {'dog': 4, 'human': 2, 'bird': 2}05 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39. Biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 cần được sử dụng cho biến chỉ mục đầu tiên có thể khái quát hóa và feet = {'dog': 4, 'human': 2, 'bird': 2}05 cần được sử dụng cho biến chỉ mục thứ hai có thể khái quát hóa

Tiếp theo là khối hỏi liệu một người có con nữa không

feet = {'dog': 4, 'human': 2, 'bird': 2}3

Tiếp theo, chúng tôi có một loạt các khối liên quan đến việc thu thập dị ứng của mọi người. Chúng có chức năng tương tự như các khối khác trong cuộc phỏng vấn này, nhưng chúng khác vì chúng sử dụng công cụ sửa đổi và biến đặc biệt feet = {'dog': 4, 'human': 2, 'bird': 2}68, đại diện cho đối tượng “chung chung”.

feet = {'dog': 4, 'human': 2, 'bird': 2}4

Biến feet = {'dog': 4, 'human': 2, 'bird': 2}68 hoạt động theo cách tương tự như cách mà các biến chỉ mục như >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 và feet = {'dog': 4, 'human': 2, 'bird': 2}05 hoạt động. Nếu docassemble muốn xác định thuộc tính feet = {'dog': 4, 'human': 2, 'bird': 2}72 cho đối tượng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']87 và đối tượng thuộc loại >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']11, thì nó có thể chạy feet = {'dog': 4, 'human': 2, 'bird': 2}75 và sau đó xử lý dòng feet = {'dog': 4, 'human': 2, 'bird': 2}76 của khối. Tương tự như vậy, nếu **docassemble muốn xác định feet = {'dog': 4, 'human': 2, 'bird': 2}78, thì nó có thể đặt feet = {'dog': 4, 'human': 2, 'bird': 2}79, đặt feet = {'dog': 4, 'human': 2, 'bird': 2}80, sau đó hỏi người xác định đó là feet = {'dog': 4, 'human': 2, 'bird': 2}82. Bằng cách sử dụng tính năng này, chúng tôi tiết kiệm được rắc rối khi viết các câu hỏi riêng biệt để thu thập các dị ứng của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83 và feet = {'dog': 4, 'human': 2, 'bird': 2}85

Cuối cùng, chúng tôi có một khối duy nhất của cuộc phỏng vấn, hiển thị cho người dùng tất cả thông tin được thu thập trong cuộc phỏng vấn

feet = {'dog': 4, 'human': 2, 'bird': 2}5

Tất cả các câu hỏi được hỏi trong cuộc phỏng vấn đều được kích hoạt bởi dòng feet = {'dog': 4, 'human': 2, 'bird': 2}87. Để lặp qua >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63, trước tiên cần xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63. Điều đó kích hoạt việc sử dụng khối đầu tiên để xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63. Sau đó, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63 cần được thu thập, bởi vì bạn không thể lặp qua một danh sách chưa được thu thập. Điều đó khiến docassemble thu thập các mục trong >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63 và làm cho chúng “hoàn thành. ” Trước khi bất kỳ >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']83 đã cho nào có thể được “đầy đủ”, tên của người đó cần được thu thập, cần thu thập thông tin về bệnh dị ứng và cần thu thập trẻ em. Trước khi một đứa trẻ có thể “hoàn chỉnh”, các bệnh dị ứng của đứa trẻ cần được thu thập. Tất cả những câu hỏi này được kích hoạt bởi vì mỗi khi màn hình tải, docassemble sẽ cố gắng hiển thị câu hỏi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'22 và mỗi lần như vậy, nó lại gặp phải câu hỏi feet = {'dog': 4, 'human': 2, 'bird': 2}87

Sau khi thu thập được >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']63, tất cả các vòng lặp “for” đều có đủ thông tin, vì vậy không cần đặt thêm câu hỏi nào nữa

Lưu ý rằng mặc dù các dòng feet = {'dog': 4, 'human': 2, 'bird': 2}98, feet = {'dog': 4, 'human': 2, 'bird': 2}99, >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet00 và >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet01 được thụt lề khi lồng vào nhau, nhưng các dòng văn bản thực sự không được thụt lề. Điều này là do thụt lề trong Markdown có ý nghĩa đặc biệt (đặc biệt là để chỉ ra rằng văn bản phải được định dạng bằng phông chữ có chiều rộng cố định). Việc thụt đầu dòng của feet = {'dog': 4, 'human': 2, 'bird': 2}98, feet = {'dog': 4, 'human': 2, 'bird': 2}99, >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet00 và >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet01 là không cần thiết, nhưng nó giúp làm cho mã dễ đọc hơn

Lưu ý rằng dòng >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet06 sử dụng thực tế là biểu diễn văn bản của a là kết quả của việc chạy phương thức trong danh sách. Vì vậy, câu kết quả có thể là “Jane Doe bị dị ứng với động vật có vỏ, đậu phộng và bụi. ”

Các loại đối tượng hỗn hợp

Nếu bạn muốn thu thập một danh sách các đối tượng không phải là cùng một loại đối tượng, bạn có thể làm như vậy bằng cách đặt thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet09 của danh sách thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 cung cấp một khối xác định thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet11 của danh sách

feet = {'dog': 4, 'human': 2, 'bird': 2}6

Trong ví dụ này, chúng tôi có một danh sách có tên là >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet12, đây là một loại. Chúng tôi có một tập hợp từ >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet16 đến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42. Điều này hướng dẫn docassemble rằng >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet12 là một danh sách các đối tượng và khi một mục mới được thêm vào danh sách, docassemble sẽ tìm kiếm giá trị của >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19 để tìm ra loại đối tượng mà mục mới sẽ là. Ngược lại, thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01 hướng dẫn docassemble rằng loại đối tượng cho mọi đối tượng mới phải là giá trị của >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01

Vì vậy, trước khi docassemble thêm một mục mới vào danh sách, nó sẽ tìm kiếm định nghĩa của >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19 và sau đó mục mà nó thêm vào danh sách sẽ là một đối tượng thuộc loại được chỉ định bởi giá trị của >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19. Sau khi mỗi mục được thêm vào, docassemble quên mất giá trị của >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19, vì vậy câu hỏi sẽ được hỏi lại cho từng mục trong danh sách

Có một vài điều cần lưu ý về điều đó xác định >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19

feet = {'dog': 4, 'human': 2, 'bird': 2}7

Đây là câu hỏi về một mục trong danh sách, nhưng lưu ý rằng chúng ta không có biến >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 để chỉ ra mục đó là gì, vì >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet11 là thuộc tính của danh sách >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet12, không phải thuộc tính của đối tượng mới (>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet30). Vì vậy, chúng ta phải sử dụng để có được số

Cũng lưu ý rằng chúng tôi đang sử dụng phương pháp để đặt giá trị của >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19 dựa trên đầu vào của người dùng. Bạn có thể nghĩ rằng sẽ đơn giản hơn nếu chỉ viết như sau

feet = {'dog': 4, 'human': 2, 'bird': 2}8

Tuy nhiên, điều này sẽ đặt >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet19 thành một đoạn văn bản (>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet34 hoặc >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet35), thay vì loại đối tượng (>>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']03 hoặc >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet37). Do đó, khi đặt >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet11 (hoặc >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01), hãy đảm bảo sử dụng mã Python

Lưu ý rằng có hai câu hỏi hỏi về các thuộc tính của các mục trong danh sách

feet = {'dog': 4, 'human': 2, 'bird': 2}9

Bạn có thể tự hỏi làm thế nào docassemble biết câu hỏi nào trong hai câu hỏi này để hỏi một mục nhất định trong danh sách >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet12. Nếu đối tượng là một >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet37, thì phần trình bày bằng văn bản của đối tượng trước tiên sẽ yêu cầu >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet42 và sau đó là >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet43. Nếu đối tượng là một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']03, trước tiên, một đại diện bằng văn bản của đối tượng sẽ yêu cầu >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet45. Khi docassemble tập hợp các mục vào một danh sách, nó sẽ hỏi bất kỳ câu hỏi nào cần thiết để xây dựng biểu diễn văn bản của mục đó. Vì vậy, nếu thuộc tính docassemble cần là >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet42, thì cả hai câu hỏi đều có khả năng xác định thuộc tính đó. Câu hỏi “Thành phố là gì” xuất hiện cuối cùng trong tệp YAML, do đó, câu hỏi này sẽ được ưu tiên hơn câu hỏi “Địa chỉ là gì” và câu hỏi này sẽ được hỏi. Nếu thuộc tính docassemble cần là >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet45, thì chỉ câu hỏi “Địa chỉ là gì” mới có khả năng xác định điều đó, vì vậy chỉ câu hỏi đó sẽ được hỏi

Quá trình thu thập các mục trong từ điển hơi khác so với quá trình thu thập các mục của một. Giống như quá trình thu thập các đối tượng, quá trình thu thập các đối tượng sẽ gọi các thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'97 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91

Ngoài ra, process sẽ tìm thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet54 để lấy key bổ sung vào từ điển. Trong ví dụ dưới đây, chúng tôi tạo một trong đó các khóa là tên của các loại trái cây và các giá trị là số lượng hạt mà trái cây đó chứa. Có 1 câu hỏi tên quả (_______22_______56) và 1 câu hỏi riêng hỏi số hạt (_______7_______38). (Khi điền a , >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 đề cập đến khóa, trong khi khi điền a , >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39 đề cập đến một số như 0, 1, 2, v.v. )

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet0

Ngoài ra, bạn có thể sử dụng thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet62 để đặt giá trị cho một mục mới

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet1

Giá trị của thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet62 sẽ không bao giờ được tìm kiếm bởi quá trình thu thập; . Vì vậy, nếu bạn muốn sử dụng >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet62, bạn cần đặt nó bằng một câu hỏi đồng thời đặt >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet54, như trong ví dụ trên

Thu thập một từ điển các đối tượng

Bạn cũng có thể điền nội dung của một trong đó mỗi giá trị chính là một đối tượng

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet2

Trong ví dụ trên, chúng tôi điền vào một tên gọi là >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet69, trong đó các phím là một loại vật nuôi (e. g. , >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet70, question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any4) và các giá trị là các đối tượng thuộc loại có thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet73 (e. g. , >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet74, >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet75) và >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet76 (e. g. , mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.9). Chúng ta cần bắt đầu bằng cách nói với docassemble rằng the là một từ điển của các đối tượng. Chúng tôi làm điều này bằng cách đặt thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01 của thành. Sau đó, chúng tôi cung cấp một câu hỏi thiết lập thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet54

Khi một >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01 được cung cấp, docassemble sẽ đảm nhiệm việc khởi tạo giá trị của mỗi mục nhập dưới dạng một đối tượng thuộc loại này. Nó cũng sẽ tự động thu thập bất kỳ thuộc tính nào, nếu có, cần thiết để thể hiện đối tượng dưới dạng văn bản. Biểu diễn của đối tượng dưới dạng văn bản là những gì bạn nhìn thấy nếu đưa đối tượng vào mẫu Mako. >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet84. (Hoặc, nếu bạn biết Python, nó là kết quả của >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet85. ) Các thuộc tính cần thiết để biểu diễn đối tượng dưới dạng văn bản phụ thuộc vào loại đối tượng. Trong trường hợp a , không cần thuộc tính nào để biểu diễn đối tượng dưới dạng văn bản. Trong trường hợp là , tên của cá nhân là bắt buộc (tối thiểu ____22_______88)

Vì a không có bất kỳ thuộc tính cần thiết nào nên trong ví dụ trên, đối tượng >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet69 được coi là “đã thu thập” (i. e. >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet91 là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42) sau tất cả các loại vật nuôi (e. g. , >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet70, question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any4) đã được cung cấp. Tại thời điểm này, các giá trị của s chỉ đơn giản là rỗng. Các thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet73 và >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet76 vẫn chưa được xác định. Màn hình cuối cùng của cuộc phỏng vấn, bao gồm một vòng lặp “for” mô tả số chân của mỗi con vật cưng, khiến việc đặt câu hỏi thu được các thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet76 và >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet73

Việc tập hợp các mục vào một cũng giống như việc tập hợp các mục vào một. Sự khác biệt là thay vì sử dụng các thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet54 và >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet62, bạn sử dụng một thuộc tính duy nhất, >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])05

Dưới đây là một ví dụ tập hợp một tập hợp các mục văn bản (e. g. , mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.1, mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.3, >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])08) thành một

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet3

Bạn cũng có thể tập hợp các đối tượng vào một. Tuy nhiên, the không sử dụng thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']01, cũng như các nhóm sử dụng. Các đối tượng mà bạn thu thập thành một nhu cầu đã tồn tại

Trong ví dụ bên dưới, chúng tôi tạo một số s, mỗi số đại diện cho một loại trái cây và chúng tôi sử dụng câu hỏi trắc nghiệm với >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])17 được đặt thành >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])18 để hỏi người dùng thích loại trái cây nào. (Xem để biết thêm thông tin về các loại câu hỏi này. )

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet4

Trong các ví dụ trên, quá trình đặt câu hỏi điền vào danh sách được kích hoạt hoàn toàn bằng mã như >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])19, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'25 hoặc >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])21

Nếu bạn muốn đặt câu hỏi vào một thời điểm cụ thể, bạn có thể làm như vậy bằng cách tham khảo >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'28. (Đằng sau hậu trường, đây là phương pháp tương tự được sử dụng khi quá trình được kích hoạt ngầm. )

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet5

Phương thức chấp nhận một số đối số từ khóa tùy chọn

  • >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])24 có thể được đặt thành số lượng mục tối thiểu bạn muốn thu thập. Thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'97 sẽ không được tìm kiếm. Thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91 sẽ được tìm kiếm sau khi đạt đến con số tối thiểu này
  • >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])27 có thể được đặt thành tổng số mục bạn muốn thu thập. Thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91 sẽ không được tìm kiếm
  • >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])29 có thể được đặt thành loại đối tượng mà mỗi thành phần của nhóm phải là. (Điều này không có sẵn cho các đối tượng. )
  • >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']48 có thể được đặt thành tên của một thuộc tính cần được tìm kiếm cho mỗi mục trong quá trình thu thập. Bạn cũng có thể đặt thuộc tính của chính đối tượng nhóm

Phương pháp này không phải là cách duy nhất mà quá trình thu thập có thể được kích hoạt. Thuộc tính >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])34 kiểm soát xem phương thức có được gọi hay không. Nếu >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])34 là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 (là giá trị mặc định), thì quy trình thu thập sẽ được kích hoạt bằng cách sử dụng. Nếu >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])34 là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58, quy trình thu thập sẽ được kích hoạt theo cách đơn giản hơn. bằng cách tìm kiếm giá trị của >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])41. Vì vậy, bạn có thể cung cấp một bộ mà đặt >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])41 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42. Ví dụ

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet6

Đặt >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])41 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 có nghĩa là khi bạn cố gắng lấy độ dài của nhóm hoặc lặp qua nó, docassemble sẽ cho rằng không cần phải làm gì thêm để thêm các mục vào nhóm. Bạn vẫn có thể thêm nhiều mục hơn vào danh sách nếu muốn, sử dụng s

Ở mức rất cơ bản, việc thu thập danh sách những thứ từ người dùng không phức tạp. Ví dụ, bạn có thể làm điều này

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet7

Ví dụ này sử dụng hàm tích hợp của Python, trả về danh sách các số nguyên bắt đầu bằng đối số thứ nhất và nhỏ hơn đối số thứ hai. Ví dụ

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet8

Lặp qua tất cả các số sử dụng biến >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])50, tìm kiếm >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])51. Mục đầu tiên nó tìm kiếm là mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0. Vì điều này chưa được xác định, cuộc phỏng vấn sẽ tìm kiếm một câu hỏi đưa ra để xác định mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0. Nó không tìm thấy bất kỳ câu hỏi nào xác định mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0, vì vậy, nó sẽ tìm kiếm một câu hỏi cung cấp cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'38 đã xác định. Nó tìm thấy câu hỏi này và hỏi nó từ người dùng. Sau khi người dùng cung cấp câu trả lời, nó sẽ chạy lại. Lần này, mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0 đã được xác định. Nhưng trong lần lặp lại tiếp theo của , cuộc phỏng vấn tìm kiếm mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.2 và thấy rằng nó không được xác định. Vì vậy, cuộc phỏng vấn lặp lại quy trình với mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.2. Khi tất cả các >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])51 được xác định, câu hỏi >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'22 có thể được hiển thị cho người dùng và cuộc phỏng vấn kết thúc

Một cách khác để đặt câu hỏi là hỏi từng mục một và sau mỗi mục, hãy hỏi xem có mục nào khác không

>>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet9

Để thu thập danh sách theo cách thủ công, cần phải

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])0

Ví dụ này sử dụng một chút mã Python để đặt câu hỏi thích hợp

Một số biến được khởi tạo

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])1

Sau đó, thuật toán chính là

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])2

Vì >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])63 được khởi tạo là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'48, nên biến không xác định đầu tiên mà mã này gặp phải là mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0. Khi đoạn mã gặp mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0, nó sẽ tìm kiếm giá trị của mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0 và câu hỏi “What’s the first fruit?” . Một khi mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.0 được xác định, cuộc phỏng vấn sẽ hủy xác định >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])63, nhưng sau đó khi vòng lặp >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])70 lặp lại, thì cần phải xác định >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])63. Vì >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])63 không được xác định, cuộc phỏng vấn đưa ra cho người dùng câu hỏi >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])73, trong đó hỏi "Có nhiều trái cây hơn không?"

Điều này đang bắt đầu trở nên phức tạp. Và mọi thứ thậm chí còn phức tạp hơn khi bạn muốn nói những câu như “Có tất cả ba loại trái cây” và “Bạn đã nói với tôi về ba loại trái cây cho đến nay” trong các câu hỏi phỏng vấn của bạn. Trong trường hợp “Có tất cả ba loại trái cây”, điều kiện tiên quyết để nói điều này là đảm bảo rằng người dùng đã cung cấp danh sách đầy đủ. Nhưng trong trường hợp “Bạn đã nói với tôi về ba loại trái cây cho đến nay,” bạn sẽ không muốn điều kiện tiên quyết này

Vì việc yêu cầu người dùng cung cấp danh sách mọi thứ có thể trở nên phức tạp nên docassemble có một tính năng tự động hóa quy trình đặt câu hỏi cần thiết để điền đầy đủ danh sách

Nếu danh sách của bạn là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12, thì có ba thuộc tính đặc biệt. >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])78, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'37 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40. Thuộc tính >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])78 ban đầu không được xác định, nhưng được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 khi danh sách được điền đầy đủ. Thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'37 được sử dụng để hỏi người dùng xem danh sách có trống không. Thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40 được sử dụng để đặt câu hỏi cho người dùng như “Bạn đã nói với tôi về ba loại trái cây cho đến nay. táo, đào và lê. Có thêm trái cây nào không?”

Ngoài hai thuộc tính này, còn có một phương pháp đặc biệt, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'28, phương thức này sẽ đưa ra các câu hỏi thích hợp và sẽ trả về >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 khi danh sách đã được điền đầy đủ. Phương pháp tìm kiếm các định nghĩa cho >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])88, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'38 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40. Nó làm cho >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'40 không được xác định khi cần thiết

Đây là một ví dụ hoàn chỉnh

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another

docassemble gọi ngầm >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'29 trong nhiều trường hợp, chẳng hạn như khi bạn gọi >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])93, >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])94 hoặc >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])95. Trong một số trường hợp, bạn có thể muốn sử dụng mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'03 hoặc >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'06 trong khi quá trình thu thập vẫn đang diễn ra hoặc chưa được bắt đầu

Để kiểm tra xem một nhóm đã được tập hợp chưa, bạn có thể gọi nó. Điều này sẽ trả về >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 nếu nhóm đã được tập hợp và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58 nếu không

Để kiểm tra xem quá trình thu thập đã được bắt đầu hay chưa, bạn có thể truy cập vào thuộc tính

Để có được số lượng mục trong một nhóm mà không kích hoạt quá trình thu thập, hãy gọi. Điều này sẽ trả về số lượng vật phẩm được thu thập cho đến nay

Để sắp xếp một nhóm ngay cả khi nó chưa được tập hợp đầy đủ, hãy gọi thay vì

Các đối tượng mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'03 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'06 có một thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another09 là một Python đơn giản objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another10, objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another11 hoặc objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another12 chứa các mục trong nhóm. Để bỏ qua các tính năng đặc biệt của mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'03 và >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'06, bạn có thể truy cập trực tiếp vào objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another09 và quy trình thu thập danh sách sẽ không được kích hoạt

Khi quá trình thu thập vẫn đang diễn ra và nhóm của bạn chứa đồ vật, objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another09 có thể chứa một hoặc nhiều đồ vật không sử dụng được. Ví dụ: khi cuộc phỏng vấn đang trong quá trình yêu cầu mục thứ năm trong nhóm, bạn có thể muốn hiển thị cho người dùng bốn mục đầu tiên. Tuy nhiên, nếu bạn cố lặp lại objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another09 và hiển thị thông tin về từng mục, bạn có thể thấy mình đang ở trong Catch-22 vì mã của bạn mong muốn các thuộc tính của mục thứ năm được xác định khi các thuộc tính đó được xác định bởi chính mục mà bạn đang cố gắng xác định. . Thay vì truy cập objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another09, bạn có thể gọi. Điều này sẽ trả về một mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'03, hoặc >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'06 chỉ chứa các phần tử “đầy đủ. ” Việc một mục có “đầy đủ” hay không tùy thuộc vào việc nhóm đó có. Nếu nhóm có , một mục trong nhóm sẽ được coi là "đầy đủ" nếu mục đó có một thuộc tính theo tên của. Nếu nhóm không có , một mục sẽ được coi là "hoàn thành" nếu nó có thể được rút gọn thành văn bản mà không gặp biến không xác định. Ví dụ: một đối tượng có thể được rút gọn thành văn bản nếu thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet88 được xác định, vì vậy nếu một _____________32 được gọi chứa một số đối tượng, objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another34 sẽ trả về a chỉ chứa các đối tượng đó trong đó _______88 được xác định

Trong lập trình máy tính, một “vòng lặp for” cho phép bạn thực hiện lặp đi lặp lại một việc gì đó, chẳng hạn như lặp qua từng mục trong danh sách

Ví dụ, đây là một ví dụ trong Python

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])4

Đoạn mã này “lặp” qua các phần tử của objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another37 và tính tổng số tiền. Ở cuối, objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another38 được in

Đối với các vòng lặp dựa trên , , và các đối tượng có thể được đưa vào nội dung văn bản bằng cách sử dụng câu lệnh >>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])49/objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another43 Mako

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])5

Các vòng lặp “for” của Mako hoạt động giống như các vòng lặp for của Python, ngoại trừ việc chúng cần được kết thúc bằng “endfor. ”

Nếu danh sách có thể trống, bạn có thể kiểm tra độ dài của nó bằng cách sử dụng câu lệnh objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another44/objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another45/objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another46 Mako

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])6

Bạn cũng có thể sử dụng phương pháp

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])7

Bạn có thể kiểm tra xem thứ gì đó có trong danh sách hay không bằng cách sử dụng câu lệnh có dạng objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another44 … objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another49

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])8

Để biết thêm thông tin về “vòng lặp for” trong Mako, hãy xem

Có thể cho phép người dùng của bạn chỉnh sửa danh sách đã được thu thập. Đây là một ví dụ

>>> colors = set(['blue', 'green', 'red']) >>> colors set(['blue', 'green', 'red']) >>> colors.add('blue') >>> colors set(['blue', 'green', 'red']) >>> colors.remove('red') >>> colors set(['blue', 'green'])9

Điều này hoạt động bằng cách sử dụng hai tính năng

  1. Công cụ xác định objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another51 trên khối, bổ sung cột “Hành động” vào bảng và cho biết màn hình nào sẽ được hiển thị khi người dùng nhấp vào nút “Chỉnh sửa”. Đầu tiên, một màn hình sẽ được hiển thị yêu cầu thuộc tính >>> feet = {'dog': 4, 'human': 2, 'bird': 2} >>> feet['dog'] 4 >>> feet['human'] 2 >>> feet['bird'] 2 >>> feet.keys() ['dog', 'human', 'bird'] >>> feet.values() [4, 2, 2] >>> for key, val in feet.items(): .. print("{animal} has {feet} feet".format(animal=key, feet=val)) .. dog has 4 feet human has 2 feet bird has 2 feet88. Sau đó, một màn hình sẽ được hiển thị yêu cầu thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another54
  2. Phương thức objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another55 trên HTML chèn một nút mà người dùng có thể nhấn để thêm một mục nhập vào danh sách đã được thu thập

Bạn có thể cho phép người dùng của mình chỉnh sửa từ một nút chỉnh sửa trong một trang

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another0

Thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another59 của a là đặc biệt; . Bởi vì lúc đầu objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another59 không được xác định, khối sẽ không hiển thị nút “Chỉnh sửa” cho danh sách cho đến khi danh sách được thu thập. Khi danh sách đã được thu thập và người dùng nhấp vào nút "Chỉnh sửa" được liên kết với objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another59, người dùng sẽ được đưa đến khối với objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another67. Trên màn hình này, bạn có thể hiển thị danh sách dưới dạng bảng và cung cấp nút objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another55 nếu bạn muốn người dùng có thể thêm mục nhập

Cũng có thể đưa một bảng có thể chỉnh sửa trực tiếp vào trang đánh giá

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another1

Dòng objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another69 rất quan trọng ở đây. Một mục trong danh sách objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another58 sẽ không được hiển thị nếu nó chứa bất kỳ biến không xác định nào. Sự hiện diện của một biến không xác định trong một mục danh sách objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another58 sẽ không khiến docassemble tìm kiếm định nghĩa của biến đó (trừ khi sử dụng trình xác định objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another72). Do đó, nếu bạn muốn hiển thị một mục objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another58 có chứa một objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another52, bạn cần đảm bảo rằng biến đại diện cho objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another52 được xác định theo thời gian mà bạn muốn bảng có thể chỉnh sửa được. Trong ví dụ này, objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another69 đảm bảo rằng biến đại diện cho bảng được xác định trước khi người dùng có cơ hội xem lại câu trả lời của mình

Mặc dù các ví dụ trên có tất cả các bảng đặc trưng để chỉnh sửa đối tượng mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7, nhưng đặc điểm objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another51 cũng có thể được sử dụng khi objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another79 của tham chiếu đến một

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another2

Nếu của bạn không được tạo thành từ các đối tượng, nó có thể được chỉnh sửa bằng cách đặt objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another51 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 thay vì thành danh sách các thuộc tính

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another3

Bạn có thể làm tương tự với các nhóm không sử dụng đồ vật

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another4

Tùy chỉnh giao diện chỉnh sửa

Nếu bạn không muốn người dùng của mình có thể xóa các mục, bạn có thể thêm objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another86 vào

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another5

Hoặc, nếu bạn muốn người dùng của mình có thể xóa các mục nhưng không thể chỉnh sửa các mục, bạn có thể bao gồm objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another88 và không bao gồm objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another51

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another6

Nếu bạn muốn cho phép người dùng của mình xóa các mục, nhưng chỉ khi nhóm dài hơn một độ dài nhất định, bạn có thể cung cấp thuộc tính hoặc

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another7

Nếu bạn có a hoặc a và bạn muốn người dùng xác nhận trước khi xóa một mục rằng họ thực sự muốn xóa mục đó, bạn có thể bao gồm objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another95

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another8

Nếu bạn muốn các mục cụ thể được bảo vệ để không bị chỉnh sửa và/hoặc xóa, bạn có thể đặt mã xác định objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another96

objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another9

Trong ví dụ này, thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another97 của bảng >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'12 xác định xem mục đó có phải là “chỉ đọc” hay không. Hai mục đầu tiên trong mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.7, được thêm vào danh sách trong khối >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'11, có thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another97 được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, trong khi các mục được thêm bởi người dùng có thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another97 được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58. Vì objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another96 được đặt thành objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another97, các nút objects: - fruit: DAList07 và objects: - fruit: DAList08 không khả dụng cho các mục có thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another97 được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42

Nếu bạn muốn cho phép chỉnh sửa nhưng không xóa hoặc ngược lại, giá trị của thuộc tính có thể được đặt thành từ điển Python thay vì giá trị >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 hoặc >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58. Nếu giá trị của khóa objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another51 là sai, nút “Chỉnh sửa” sẽ không hiển thị. Nếu giá trị của khóa objects: - fruit: DAList14 là sai, nút “Xóa” sẽ không hiển thị

objects: - fruit: DAList0

Thông thường, việc tạo bảng yêu cầu phải hoàn tất quá trình thu thập. Tuy nhiên, nếu quá trình thu thập đang diễn ra, thì bảng vẫn sẽ được tạo và nó sẽ chỉ chứa các mục “hoàn thành. ” Nếu bạn không muốn bảng kích hoạt quá trình thu thập, hãy đặt objects: - fruit: DAList15

Nếu bạn có một định nghĩa objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another52 bao gồm các thành phần có thể chỉnh sửa (i. e. objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another51, objects: - fruit: DAList18), nhưng bạn muốn trình bày bảng với các tính năng chỉnh sửa trong một số ngữ cảnh nhưng không có tính năng chỉnh sửa trong các ngữ cảnh khác, bạn có thể bao gồm bảng bằng cách gọi phương thức objects: - fruit: DAList19 với objects: - fruit: DAList20 để ẩn các tính năng chỉnh sửa

objects: - fruit: DAList1

Nếu bạn có và bạn muốn cho phép người dùng thay đổi thứ tự các mục trong danh sách, bạn có thể đặt objects: - fruit: DAList22 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42

objects: - fruit: DAList2

Các thay đổi về thứ tự các phần tử sẽ được lưu lại khi người dùng nhấn Tiếp tục

Theo mặc định, khi thu thập hoặc chỉnh sửa một mục danh sách, docassemble chỉ hỏi về một mục danh sách tại một thời điểm. Nếu bạn có một cái có chứa một bộ xác định và cái đó sử dụng các biến lặp (>>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'39, feet = {'dog': 4, 'human': 2, 'bird': 2}05, feet = {'dog': 4, 'human': 2, 'bird': 2}62, v.v. ) trong tên biến, bạn có thể sử dụng objects: - fruit: DAList29 để mở rộng phần này trên màn hình để người dùng có thể nhập câu trả lời cho nhiều mục danh sách trên một màn hình

objects: - fruit: DAList3

Trình xác định objects: - fruit: DAList29 có thể được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58 hoặc mã Python đánh giá thành giá trị đúng hoặc sai. Nếu giá trị là true, giá trị sẽ được mở rộng;

Một hạn chế của tính năng objects: - fruit: DAList29 là bạn không thể sử dụng tạo khuôn mẫu Mako trên nhãn trường, nếu không sẽ xảy ra lỗi

Bạn có thể tùy chỉnh hành vi của bằng cách đặt objects: - fruit: DAList29 thành từ điển

Các khóa có sẵn cho từ điển là

  • objects: - fruit: DAList39. đây có thể là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58 hoặc mã Python đánh giá thành giá trị đúng hoặc sai. Nếu giá trị là true, giá trị sẽ được mở rộng; . (Giá trị này giống với giá trị của phiên bản tốc ký của objects: - fruit: DAList29 đã thảo luận ở trên. ) Nếu objects: - fruit: DAList29 là một từ điển và objects: - fruit: DAList39 bị bỏ qua, giá trị mặc định là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42
  • objects: - fruit: DAList48. cái này có thể được đặt thành nhãn văn bản Mako cho từng mục trên màn hình. Nếu là objects: - fruit: DAList49, các mặt hàng sẽ được dán nhãn “Trái cây 1,” “Trái cây 2,” v.v.
  • objects: - fruit: DAList50. đây có thể là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58 hoặc mã Python đánh giá thành giá trị đúng hoặc sai. Nếu giá trị là true, thì thuộc tính objects: - fruit: DAList53 sẽ được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42 khi người dùng nhấn nút Tiếp tục. Giá trị mặc định là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42
  • objects: - fruit: DAList56. đây có thể là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58 hoặc mã Python đánh giá thành giá trị đúng hoặc sai. Nếu giá trị là true, thì người dùng được phép thêm các mục bổ sung vào danh sách. Nếu giá trị là sai, người dùng chỉ có thể chỉnh sửa các mục hiện có. Giá trị mặc định là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42
  • objects: - fruit: DAList60. đây có thể là >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58 hoặc mã Python đánh giá thành giá trị đúng hoặc sai. Nếu giá trị là true, thì người dùng được phép xóa các mục hiện có khỏi danh sách. Nếu sai, người dùng sẽ không thấy bất kỳ nút “Xóa” nào ngoại trừ các mục xuất hiện do người dùng đã nhấp vào nút “Thêm mục khác”
  • objects: - fruit: DAList63. bạn có thể đặt văn bản này thành văn bản sẽ được sử dụng "Thêm mục khác" cho nút thêm mục khác vào danh sách. Văn bản mặc định có thể được thay đổi trên toàn cầu bằng tính năng

Đây là một ví dụ

objects: - fruit: DAList4

Ví dụ này minh họa cách bạn có thể sử dụng thuộc tính objects: - fruit: DAList39 để chỉ ra rằng nên sử dụng phương pháp thu thập nhiều mục để thu thập danh sách ban đầu, nhưng phương pháp một mục trên mỗi màn hình thông thường nên được sử dụng để chỉnh sửa các thành phần danh sách hoặc thêm mới

Nếu bạn đặt thuộc tính objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another92 trên thành 3, thì ba mục đầu tiên trong danh sách sẽ không có nút Xóa

Trình xác định objects: - fruit: DAList29 chỉ hoạt động trên các biến, không hoạt động trên hoặc các biến

Khi bạn đang tập hợp một nhóm, bạn có thể muốn một số mã chạy sau khi nhóm được tập hợp, cũng như bất cứ khi nào một mục trong nhóm được chỉnh sửa hoặc xóa

Nếu mã bạn cần chạy chỉ liên quan đến một mục trong nhóm, bạn có thể đặt thành objects: - fruit: DAList73 và viết mã xác định thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit.append('grape') >>> fruit ['apple', 'orange', 'pear', 'grape'] >>> sorted(fruit) ['apple', 'grape', 'orange', 'pear']68 cho bất kỳ mục nào trong nhóm. Điều này sẽ được chạy cho mọi mục trong nhóm trong quá trình thu thập và bất cứ khi nào người dùng trong nhóm

Tuy nhiên, đôi khi mã bạn muốn chạy liên quan đến toàn bộ nhóm chứ không chỉ một mặt hàng cụ thể. Trong trường hợp này, bạn có thể sử dụng các phương pháp "hook" và. Để sử dụng các phương thức này, bạn sẽ cần định nghĩa lớp của riêng mình bằng cách sử dụng tệp mô-đun và đặt lớp của bạn thành lớp con của bất kỳ lớp nào bạn đang sử dụng (e. g. , , )

Đây là một ví dụ phân lớp con của

objects: - fruit: DAList5

Tệp mô-đun được tham chiếu trong khối, objects: - fruit: DAList83, trông như thế này

objects: - fruit: DAList6

Trong ví dụ này, phương pháp đảm bảo rằng người dùng cung cấp giải thích về thu nhập của họ nếu người dùng được tuyển dụng, nhận trợ cấp công và tổng thu nhập từ các nguồn thu nhập này vượt quá 2.000 đô la

Phương thức thực hiện tính toán sử dụng tất cả các mục trong từ điển

Ưu điểm của việc đưa logic này vào các phương thức “hook” là logic sẽ được áp dụng tự động bất cứ khi nào có thay đổi đối với các mục trong từ điển. Ví dụ: nếu người dùng đặt thu nhập dưới 2.000 đô la lần đầu tiên nhưng sau đó chỉnh sửa danh sách để tăng thu nhập, câu hỏi bổ sung sẽ được đặt ra. Nếu người dùng chỉnh sửa danh sách để giảm thu nhập xuống dưới 2.000 đô la, thì thuộc tính có câu trả lời cho câu hỏi đó sẽ bị xóa. Bất cứ khi nào có thay đổi đối với danh sách, thì objects: - fruit: DAList86 được cập nhật

Phương thức này được chạy ngay trước khi từ điển được đánh dấu là đã thu thập. Mỗi khi người dùng chỉnh sửa bảng, từ điển tạm thời được đánh dấu là chưa được thu thập và sau đó được đánh dấu là đã được thu thập lại. Vì không thể đánh dấu từ điển là đã thu thập cho đến khi phương thức chạy hoàn tất, nên bạn có thể chắc chắn rằng thuộc tính objects: - fruit: DAList89 sẽ được xác định (hoặc không xác định nếu thích hợp)

Ngược lại, phương thức được chạy sau khi từ điển được đánh dấu là đã thu thập. Nó được đảm bảo để chạy sau khi nhóm được tập hợp hoặc tập hợp lại. Không giống như , nó không thể kích hoạt yêu cầu hoặc , ít nhất là không theo cách đáng tin cậy

Trong ví dụ này, phương thức tính tổng. Điều này được thực hiện cho mục đích trình diễn chỉ. Trong thực tế, nếu bạn chỉ cần tính tổng, tốt nhất bạn nên viết một phương thức riêng cho việc này, sau đó gọi phương thức đó bất cứ khi nào bạn cần tính tổng. (Bạn cũng có thể viết mã nội tuyến để tính tổng. ) Bạn có thể muốn sử dụng cho mã gọi API hoặc mã khác không chạy một cách không cần thiết

Lưu ý rằng vì được gọi trong quá trình thu thập, nên cẩn thận không làm bất cứ điều gì phụ thuộc vào nhóm đang được thu thập. Ví dụ: nó đề cập trực tiếp đến từ điển objects: - fruit: DAList --- mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }. --- question: | Are there any fruit that you would like to add to the list? yesno: fruit.there_are_any --- question: | What fruit should be added to the list? fields: - Fruit: fruit[i] --- question: | So far, the fruits include ${ fruit }. Are there any others? yesno: fruit.there_is_another09, điều này sẽ không kích hoạt việc thu thập. Ngược lại, phương pháp giả định (chính xác) rằng nhóm đã được thu thập

Phân lớp the là một kỹ thuật nâng cao của Python, nhưng cuối cùng thì cách dễ nhất là viết logic của bạn ở dạng “móc”, bởi vì nếu không, bạn phải cố gắng dự đoán tất cả các cách khác nhau mà người dùng có thể vượt qua logic của bạn bằng cách chỉnh sửa,

Danh sách từ điển từ hộp kiểm

Dưới đây là một ví dụ về cuộc phỏng vấn sử dụng hộp kiểm để xác định mục nào sẽ được sử dụng trong từ điển

objects: - fruit: DAList7

Điền trước một danh sách

Dưới đây là một ví dụ về cuộc phỏng vấn điền vào danh sách có hai mục trước khi cho phép người dùng thêm các mục khác

objects: - fruit: DAList8

Cuộc phỏng vấn này lợi dụng thực tế là quy trình thu thập tự động sẽ tìm kiếm định nghĩa về thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'97. Nó sử dụng khối mã xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'97 để điền vào danh sách các đối tượng

Lưu ý rằng mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.02 được gọi là. Dòng này không cần thiết trong cuộc phỏng vấn này, nhưng nó minh họa một cách làm tốt. Các khối mã trong docassemble thường cần phải là; . Các khối mã thường khởi động lại vì khi gặp một biến không xác định và định nghĩa được truy xuất từ ​​người dùng hoặc từ một khối mã khác, khối mã ban đầu không tiếp tục ở nơi nó đã dừng lại mà bắt đầu lại từ đầu

Ngoài ra, bạn có thể điền sẵn danh sách bằng cách sử dụng mã khi bắt đầu cuộc phỏng vấn để thêm các mục vào danh sách. Sau đó, cuộc phỏng vấn thậm chí sẽ không bao giờ tìm kiếm định nghĩa về thuộc tính >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'97. Tuy nhiên, phương pháp được mô tả ở trên rất hữu ích trong trường hợp danh sách được khởi tạo không tồn tại khi bắt đầu cuộc phỏng vấn, như trường hợp nếu danh sách là mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.05

Postpopulate một danh sách

Dưới đây là một ví dụ về cuộc phỏng vấn điền vào danh sách có hai mục nhập sau khi người dùng hoàn tất việc thêm mục nhập

objects: - fruit: DAList9

Cuộc phỏng vấn này sử dụng các khối mã để xác định mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.06 và mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.07. Thay vì đặt câu hỏi trực tiếp cho người dùng để xác định các biến này, cuộc phỏng vấn sẽ đặt câu hỏi xác định các biến mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.08 và mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.09. Sau đó, nó có thể sử dụng mã để làm mọi việc tùy thuộc vào câu trả lời là gì

Nếu người dùng nói rằng anh ta không có thứ yêu thích nào, cuộc phỏng vấn sẽ thêm món bánh mẹ và táo vào mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.10. Nếu người dùng mô tả một số thứ yêu thích và sau đó nói rằng anh ta không có thứ yêu thích nào khác, thì cuộc phỏng vấn sẽ thêm bánh mẹ và bánh táo vào danh sách

Lưu ý rằng nếu người dùng nói rằng anh ta không có thứ yêu thích nào, cuộc phỏng vấn sẽ đặt >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91 thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'58. Điều này là cần thiết để thuyết phục tính năng thu thập tự động rằng danh sách được thu thập đầy đủ

Lưu ý việc sử dụng để không xác định mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.09 ngay khi nó được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42. Điều này là do hệ thống thu thập tự động sẽ cần đặt lại câu hỏi và nếu mandatory: True question: | There are ${ fruit.number_as_word() } fruits in all. subquestion: | The fruits are ${ fruit }.09 đã được đặt thành >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'42, danh sách những thứ yêu thích của người dùng sẽ là vô hạn. Tương tự, đằng sau hậu trường, quá trình thu thập tự động không xác định >>> fruit = ['apple', 'orange', 'pear'] >>> fruit[0] 'apple' >>> fruit[1] 'orange' >>> fruit[2] 'pear'91 sau khi nó được xác định

Danh sách () trong Python là gì?

Danh sách. Danh sách được dùng để lưu trữ nhiều mục trong một biến duy nhất . Danh sách là một trong 4 loại dữ liệu tích hợp trong Python được sử dụng để lưu trữ các bộ sưu tập dữ liệu, 3 loại còn lại là Tuple, Set và Dictionary, tất cả đều có chất lượng và cách sử dụng khác nhau.

myList có nghĩa là gì trong Python?

myList = [1, 2, 3, 4, 5] #Đây là danh sách. print(type(myList)) Chúng ta có thể lưu trữ bất kỳ loại giá trị nào trong danh sách . Ví dụ, chúng ta có thể lưu trữ một danh sách các chuỗi. Hoặc chúng ta có thể tạo một danh sách có cả số và chuỗi.

Điều nào sau đây đại diện cho nhóm phần tử hoặc mục trong Python?

TUPLE. A Tuple is a python sequence which stores a group of elements or items.

Chủ đề