Skip to content

Commit a4760ef

Browse files
authored
gh-128720: Fix doc inacurracy about __main__.__file__ existence in the REPL (#128721)
Fix doc inacurracy about __main__.__file__ existence in the REPL
1 parent 01d9150 commit a4760ef

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Doc/library/__main__.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ Here is an example module that consumes the ``__main__`` namespace::
292292
if not did_user_define_their_name():
293293
raise ValueError('Define the variable `my_name`!')
294294

295-
if '__file__' in dir(__main__):
296-
print(__main__.my_name, "found in file", __main__.__file__)
297-
else:
298-
print(__main__.my_name)
295+
print(__main__.my_name)
299296

300297
Example usage of this module could be as follows::
301298

@@ -330,7 +327,7 @@ status code 0, indicating success:
330327
.. code-block:: shell-session
331328
332329
$ python start.py
333-
Dinsdale found in file /path/to/start.py
330+
Dinsdale
334331
335332
Note that importing ``__main__`` doesn't cause any issues with unintentionally
336333
running top-level code meant for script use which is put in the
@@ -361,8 +358,5 @@ defined in the REPL becomes part of the ``__main__`` scope::
361358
>>> namely.print_user_name()
362359
Jabberwocky
363360

364-
Note that in this case the ``__main__`` scope doesn't contain a ``__file__``
365-
attribute as it's interactive.
366-
367361
The ``__main__`` scope is used in the implementation of :mod:`pdb` and
368362
:mod:`rlcompleter`.

0 commit comments

Comments
 (0)