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
  • 40
  • 6

1 Answers1

1

Use the standard library package importlib:

import importlib
import sys
vt = importlib.import_module(sys.argv[2])
mousetail
  • 7,009
  • 4
  • 25
  • 45