File tree Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Expand file tree Collapse file tree 1 file changed +2
-8
lines changed Original file line number Diff line number Diff line change @@ -292,10 +292,7 @@ Here is an example module that consumes the ``__main__`` namespace::
292
292
if not did_user_define_their_name():
293
293
raise ValueError('Define the variable `my_name`!')
294
294
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)
299
296
300
297
Example usage of this module could be as follows::
301
298
@@ -330,7 +327,7 @@ status code 0, indicating success:
330
327
.. code-block :: shell-session
331
328
332
329
$ python start.py
333
- Dinsdale found in file /path/to/start.py
330
+ Dinsdale
334
331
335
332
Note that importing ``__main__ `` doesn't cause any issues with unintentionally
336
333
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::
361
358
>>> namely.print_user_name()
362
359
Jabberwocky
363
360
364
- Note that in this case the ``__main__ `` scope doesn't contain a ``__file__ ``
365
- attribute as it's interactive.
366
-
367
361
The ``__main__ `` scope is used in the implementation of :mod: `pdb ` and
368
362
:mod: `rlcompleter `.
You can’t perform that action at this time.
0 commit comments