Skip to content

Top-level functions and variables not visible in local scopes #10

Description

@anthonykozar

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:

def foo():
  print("foo")

def bar():
  foo()
  print("bar")

bar()

The call to foo() from bar() raises NameError 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 but globals() 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions