Importing local python modules with dependencies in ScriptEditor

Hi, I’m trying to import a local module file that has a dependency into a main script in the script editor. Here is my main script:

#! python3
# env: /my/current/folder
# env: /my/python/environment

import rhinoscriptsyntax as rs
from ScriptFile import *

rs.AddPoint((1,2,3)) # works

works() # works
doesnt_work() # error: NameError: name 'rs' is not defined

The ScriptFile is:

def works():
    print("This works")

def doesnt_work():
    rs.AddPoint( (1,2,3) )
    print("This doesn't work")

The two files are stored in the same local folder ( the first #env directiory).

Why doesn’t this work?

Add import rhinoscriptsyntax as rs to the ScriptFile as well. The name rs is defined locally in the current scope. Your main script scope is different from the module scope. You would not expect a variable named my_sphere to show up and be accessible inside an imported module

Alternatively you can pass rs as an argument to the function but then that’s not common since rs does not change and can be statically accessible from many scopes

Thanks! This works after I reload the Python 3 Engine.

Edit: I thought it didn’t work because of engine not being reloaded.