0

I need to import a python file lets name it 123xzy.py My problem is that this file name starts with numbers, and changes with every use.

I tried to use the following approach:

vt=str(sys.argv[2])
import vt

but its not working. If you know a way to import a python file with a variable name please let me know.

Thank you :)

Sara Awwad
  • 11
  • 4

1 Answers1

1

Use the standard library package importlib:

import importlib
import sys
vt = importlib.import_module(sys.argv[2])
mousetail
  • 4,536
  • 2
  • 18
  • 36