a built-in function that returns the global environment
Tags
#python #sicp
Question
What does globals() do?
Answer
?
Tags
#python #sicp
Question
What does globals() do?
Answer
a built-in function that returns the global environment
If you want to change selection, open original toplevel document below and click on "Move attachment"
Parent (intermediate) annotation
Open it e function, we use a doctest function called run_docstring_examples . This function is
(unfortunately) a bit complicated to call. Its first argument is the function
to test. The second should always be the result of the expression globals() , <span>a built-in function that returns the global environment. The
third argument is True to indicate that we would like "verbose" output: a
catalog of all tests run.<span><body><html>
Original toplevel document
1.5 Control the
globals function returns a representation of the global environment, which
the interpreter needs in order to evaluate expressions.
>>> from doctest import testmod
>>> testmod()
TestResults(failed=0, attempted=2)
<span>To verify the doctest interactions for only a single function, we use a
doctest function called run_docstring_examples . This function is
(unfortunately) a bit complicated to call. Its first argument is the function
to test. The second should always be the result of the expression
globals() , a built-in function that returns the global environment. The
third argument is True to indicate that we would like "verbose" output: a
catalog of all tests run.
>>> from doctest import run_docstring_examples
>>> run_docstring_examples(sum_naturals, globals(), True)
Finding tests in NoName
Trying:
sum_naturals(10)
Expecti
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.