Update fimport.py

This commit is contained in:
2023-12-22 07:35:14 +00:00
parent 48f508dee3
commit 90cf8c55cf

View File

@@ -3,8 +3,9 @@
# Arbitrary file importing utility. Does NOT modify sys.modules # Arbitrary file importing utility. Does NOT modify sys.modules
# #
#=========================================================================== #===========================================================================
import importlib #import importlib
import os import os
import types
def fimport( filePath ): def fimport( filePath ):
# Read the file and compile the code. This will fail if the file # Read the file and compile the code. This will fail if the file
@@ -19,7 +20,7 @@ def fimport( filePath ):
rootName, ext = os.path.splitext( fileName ) rootName, ext = os.path.splitext( fileName )
# Create a new module and exec the code in it's context. # Create a new module and exec the code in it's context.
m = importlib.import_module( rootName ) m = types.ModuleType( rootName )
m.__file__ = absPath m.__file__ = absPath
exec(code, m.__dict__) exec(code, m.__dict__)