Python Forum
why globals() exits python when quit() is aliased as q
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why globals() exits python when quit() is aliased as q
#1
I was trying to set up my python so that typing 'q' or 'quit' (instead of 'quit()') will exit the python interpreter, by doing:
type(quit).__repr__ = type(quit).__call__
q=quit
But then I noticed that if I do 'globals()', it will exit the python. Can anybody tell me why this happens? Thanks!

abc12@kc-lenovo@~
26 $ python
Python 3.9.10 (main, Jan 20 2022, 22:28:26)
[GCC 11.2.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
FileNotFoundError: [Errno 2] No such file or directory: '/home/mobaxterm/kdrive/misc/dot.pythonrc.py'
>>> globals()
{'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>}
>>> type(quit).__repr__ = type(quit).__call__
>>> q=quit
>>> globals()

abc12@kc-lenovo@~
27 $
buran write May-23-2023, 06:39 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
why globals() exits python when quit() is aliased as q - by abc12346 - May-23-2023, 01:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to avoid exec(), globals(), locals(), eval() paul18fr 10 5,434 Apr-21-2021, 05:53 PM
Last Post: snippsat
  accessing globals from a function Skaperen 8 4,393 Sep-01-2018, 11:50 PM
Last Post: Skaperen
  snake game quit() ^ SyntaxError: invalid syntax arti 1 4,159 Jan-17-2018, 06:26 PM
Last Post: buran
  Use of Globals CWatters 5 4,005 Nov-13-2017, 09:00 PM
Last Post: CWatters
  Globals vs Function mcmxl22 2 3,473 Feb-04-2017, 11:38 AM
Last Post: ichabod801
  Check if an duplicate exits in a list Server94 9 7,326 Jan-31-2017, 04:56 PM
Last Post: Server94

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020