Best way to call nested functions

What I’m trying to do:
I have code that I have written in deepnote (web-based jupyter notebook) that has multiple nested functions. I would like to paste this into anvil for a multi-user app. If I place all the code in the server, then I would have to change every function call to ‘anvil.server.call(<function_name>)’ .

I would like to be able to update the app with new code from the jupyter notebook. There are a ton of functions that will be updated over time so this would be time consuming if I would have to change the function call to the anvil format every time I updated.

Is there a way to accomplish this without having to change all the function names? Should I just put all the code in the form?

Code Sample:

# this is a formatted code snippet.
# paste your code between ``` 

#this is an example of a function that calls another function (between the **), I would like to not have to change all the **get_best_contact** formats. 

def get_contact_sf(accountID):
    
    for contact in contacts['records']:
         contacts_list.append({'Id':contact['Id'],'Title':contact['Title']})
    
    contact_found, key_contact_id, contact_rank = **get_best_contact**(contacts_list)

    return contact_found, key_contact_id, contact_rank




Clone link:
share a copy of your app

Perhaps this will help?

In

remember, the function name is a string. Therefore, the name can be stored in a variable. Where, when, and how that variable gets its value is up to you.

Unless I’m misunderstanding, you do not need to do that. You only need anvil.server.call when you call from the client to the server. When you’re already in the server, just call the function the way you normally would in Python.

2 Likes

In short, functions within the server-side code can call each other using normal Python syntax. It’s only if they need to call out of the program, to Uplink code, that they need to use anvil.server.call.

1 Like

Thank you @jshaffstall & @p.colbert. I’m new to this!