1

I'm using EasyGui to allow a user to select multiple options. Each option is a function which they can run if they select it. I'm trying to use dictionaries as suggested in other threads but I'm having trouble implementing it (Module object is not callable error). Is there something I'm missing?

from easygui import *
import emdtest1
import emdtest2
import emdtest3

EMDTestsDict = {"emdtest1":emdtest1,
                "emdtest2":emdtest2,
                "emdtest3":emdtest3}

def main():
    test_list = UserSelect()
    for i in range(len(test_list)):
        if test_list[i] in EMDTestsDict.keys():
            EMDTestsDict[test_list[i]]()

def UserSelect():
    message = "Which EMD tests would you like to run?"
    title = "EMD Test Selector"
    tests = ["emdtest1",
             "emdtest2",
             "emdtest3"]
    selected_master = multchoicebox(message, title, tests)
    return selected_master

if __name__ == '__main__':
    main()
Shankar Kumar
  • 2,197
  • 6
  • 25
  • 32

2 Answers2

2

You need to import the functions rather than the module ... for example , if you have a file called emdtest1 with a defined function emdtest1, you'd use:

from emdtest1 import emdtest1
Jack
  • 21
  • 1
2

You're putting modules into the dict, when you want to put functions in it. What you're doing is the equivalent of saying

import os
os()

Which, of course, makes no sense. If emdtest1, emdtest2, and emdtest3 are .py files with functions in them, you want:

from emdtest1 import function_name

Where function_name is the name of your function.

dano
  • 91,354
  • 19
  • 222
  • 219