1

I'm trying to make a python program for a given software than will scan&run another certain python function at choice (or .py file altogether). However I can't import a function name set in a variable.

import glob

functions_list = glob.glob('*.py')
#all my python files are found
#pick any specific file to import
import a[3]

This fails with SyntaxError: invalid syntax.

Is there any way to do this? My idea is to have a TkInter selection list where I click to run the .py I selected.

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
João Mamede
  • 129
  • 12

2 Answers2

1

Why not run the script inside a subprocess using a shell command?

subprocess.call(['python', a[3])

See here for more info: https://www.pythonforbeginners.com/os/subprocess-for-system-administrators

Artur
  • 407
  • 2
  • 8
1

You should have a look at python's imp module. It enables you to dynamically load modules at runtime and then execute their functions.

Léopold Houdin
  • 1,515
  • 13
  • 18