Skip to content

Conversation

AndyTitu
Copy link
Contributor

This PR removes the by index item field updating and uses python built-in functions for providing correctness and a more authentic feel to the examples.

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants