I am running this query on python terminal and it executes fine.
>>> exec(open("GeneratePassword.py").read())
HkdgtRf
However when I try to assign that value to a variable I am getting this error.
>>> xx = exec(open("GeneratePassword.py").read())
File "<stdin>", line 1
xx = exec(open("GeneratePassword.py").read())
^
SyntaxError: invalid syntax
Please help.
CodePudding user response:
exec
in Python 2 is a statement, not a function. It doesn't return anything. The right way to do what you're doing is to make it a Python module, so you can do:
import GeneratePassword
xx = GeneratePassword.generate()
CodePudding user response:
Use the python3 For solve this type of Error