Help me understand how to access a module from form in the same directory location as the Form

What I’m trying to do:
See the attached image. I have module called Globals as per @meredydd example Anvil | Login

I can access Globals from the Main Form at the top of the package (or directory) but not from a Form at the same level in the hierarchy. So In Main Form import Globals works. From the Main subform import Globals fails to find the module.

What I’ve tried and what’s not working:
I have tried import …Globals which worked in previous themes. I have put the Globals module at the same level as Main –

Code Sample:

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

from anvil.tables import app_tables
import Globals as sitedata

class Main(MainTemplate):

Works

from anvil.tables import app_tables
import Globals as sitedata

class Site_Select_Dropdown(Site_Select_DropdownTemplate):

Fails.

Thank you –

Clone link:
share a copy of your app
Screen Shot 2024-10-05 at 10.11.39 AM

You should always trust the autocomplete for imports. Start typing from .Glob and see what suggestions it gives you. The number of dots the autocomplete suggests has always been correct for me.

2 Likes

Amazing … .Okay – thank you – why it works not sure but good enough. I cannot access it as import Globals as myname but I can access it using from …Globals import ‘*’ (or variables) - I wish I could access as an object and not just the objects properties and methods – but that is still good.

Okay so I just tried this:
from … import Globals as sitesdata and that worked! Is this documented … Thank you for the help I was just waiting to see if there was help for this question. I appreciate it – JM

The autocomplete should give you both forms of import as suggestions.

1 Like