I tried to import the file 227exercise.py
, but keep getting following error:
SyntaxError: Invalid Syntax
I tried to import the file 227exercise.py
, but keep getting following error:
SyntaxError: Invalid Syntax
You can do this with importlib
.
import importlib
module = importlib.import_module("227exercise")
print(repr(module))
# <module '227exercise' from '/home/ubuntu/227exercise.py'>
However, it is still strongly recommended that you name your python files with valid identifiers (they can't begin with digits).