I'm trying to run an example program from a Python class I'm taking. The program is a load balancer simulation, that calls a random script name. The scripts are all identical and are named 'computer1.py', 'computer2.py' and 'computer3.py'. Here's relevant parts of the code:
import computer1
import computer2
import computer3
SERVERS = ['computer1', 'computer2', 'computer3']
server = get_server()
print(server.printName())
...
The get_server() function works correctly and returns either computer1, computer2 or computer3
The script bombs out at the next line when I try to call the printName() function from the returned server (printName does exist in all three of the computer files).
I'm getting the following error:
AttributeError: 'str' object has no attribute 'printName'
The instructor was using Python 2.7 in the class so I'm guessing there is something different in 3.5 that is causing this to not work correctly.
NOTE: I don't believe this is a duplicate to the above question. I'm trying to dynamically call a different module using a variable name. If I do the following the script works properly:
print(computer1.printName())
However when I use a varaible for the call, ex:
print (server.printName())
I get the str error.