Fundamentally, your problem is that you're expecting savePath
and saveName
to be in global scope, where they are only available in the function save()
. Your immediate problem will likely be addressed just by including the line:
global saveName, savePath
at the top of the save()
function.
This is a good blog post explaining some the differences in variable scope. See also docs to Python global.
That said: global variables are often a sign of problematic design. Especially since you're taking the trouble to return savePath
and saveName
, a better solution would be to make sure you actually save these values when you return them:
(savePath, saveName) = save()
Here again, you're saving global scope -- but when you wrap that outer level of code in a function, you'll have better encapsulation.