Files
micropython/tests/cmdline/cmd_file_variable.py
Andrew Leech 3b2b8dd538 shared/runtime/pyexec: Set __file__ for file input when enabled.
When `MICROPY_MODULE___FILE__` is enabled and parsing file input, set the
global `__file__` variable to the source filename. This matches the
behavior of the unix port and provides the current filename to the
executing script.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2025-11-22 00:01:28 +11:00

6 lines
150 B
Python

# Test that __file__ is set correctly for script execution
try:
print("__file__ =", __file__)
except NameError:
print("__file__ not defined")