-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Top-level functions and variables not visible in local scopes #10
Comments
I think I have a solution to this issue now. The solution is to pass only one dictionary to exec() for both the globals and locals at the top-level. It works when I try simulating what is happening in pyonic/interpreter_subprocess/interpreter.py from a Python command line interpreter. So, something like
produces the same error as the Pyonic interpreter:
while this produces the correct output.
I haven't had the time to try to rebuild the Pyonic app with this fix but I'm reasonably confident that it will work. I can run my patched version of pyonic/interpreter_subprocess/interpreter.py from a command line and it prints out
I suspect that my computer and OS may be too old to build current versions of Kivy and/or p4a, so I expect to have to do a lot of experimention to rebuild. My attempts to simply modify the APK file haven't succeeded yet either. So, I've created a pull request with this fix and a separate commit that removes the need to import the copy module in the hope that a new official build can be produced. I realize that the project hasn't been updated in quite a while. :( More details about the solution are in the git commit message. THANKS! Anthony |
This is a problem that has been hindering my use of Pyonic interpreter for several years. I'm kind of surprised that it is not listed as a known issue or hasn't been reported yet.
Basically, in both Pyonic 2 & 3, functions that I define and variables that I assign at the top-level of the interpreter are not visible as globals within other functions (or even themselves -- no recursion). A simple example:
The call to
foo()
frombar()
raisesNameError
with the message "global name 'foo' is not defined" in Python 2.7 and "name 'foo' is not defined" in Python 3.6.dir()
shows both foo and bar butglobals()
does not. I've been working around the problem by passing in functions as default parameters to functions but this has some limitations. (For one thing, recursion doesn't work properly).I was hoping to try fixing this myself but I have no experience with Kivy or Python for Android and unfortunately don't have time to try to set up those tools.
Thanks!
Anthony Kozar
The text was updated successfully, but these errors were encountered: