Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ async def main():

print(dict(item))

# Update a field in your item
item.fields[0].value = "new_value"
updated_item = await client.items.put(item)
# Update a field in your item (change the password)
updated_item = Item(**dict(item))
next(f for f in updated_item.fields if f.title == "password").value = "new_pass"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will raise StopIteration exception if nothing is found.
We can handle it like this:

try:
    password_field = next(f for f in updated_item.fields if f.title == "password")
    password_field.value = "new_pass"
    updated_item = await client.items.put(updated_item)
except StopIteration:
    print("Password field not found")

updated_item = await client.items.put(updated_item)

print(dict(updated_item))

Expand Down
Loading