Skip to content

Commit f1ce42e

Browse files
committed
use outer_locals
1 parent f0769ae commit f1ce42e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

eval-file-pyqt5-set-value/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The C++ program defines a `set_the_answer` lambda that can receive the new value
44

55
The Python script creates an (PyQt) application that is showing an input dialog. If the _Ok_ button is pressed, the `set_the_answer()` function passes the value to the C++ code.
66

7-
It is to be noted that `pybind11` is passing the `set_the_answer()` as a local to the _eval_ (exec, in reality) Python context: we need to explicitely pass the function to the `get_the_value()` to make it visible inside of it.
8-
(This is becaue Python executes the code as if it was in a class environment... I've been told.)
7+
One big warning: the `set_the_answer()` function is not visisble inside of `get_the_value()`: `pybind11` is passing the `set_the_answer()` as a local to the _eval_ (exec, in reality) Python context: we need to explicitely pass the outer local context to the `get_the_value()`, and visible inside of it.
8+
(I've been told that this is becaue Python executes the code as if it was in a class environment...)
99

1010
~~~.sh
1111
$ mkdir build

eval-file-pyqt5-set-value/python/input-number.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
def get_the_value(locals_):
1+
def get_the_value(outer_locals):
22
from PyQt5.QtWidgets import QInputDialog
33
num, ok = QInputDialog.getInt(None, 'The number to be set', 'enter a number')
44
if ok:
5-
locals_['set_the_answer'](num)
5+
outer_locals['set_the_answer'](num)
66

77
if __name__ == '__main__':
88
from PyQt5.QtWidgets import QApplication

0 commit comments

Comments
 (0)