• Wenjarich (edited 8 years ago)
    +2

    I tried sys.exit() before, and just tried it again and got the following error,

    Traceback (most recent call last):

    File "C:\Python34\Programs\Practice\Silly Test Game.py", line 23, in <module>

    race = ChCreation.chkrace(r)

    File "C:\Python34\Programs\Practice\ChCreation.py", line 12, in chkrace

    sys.exit()

    NameError: name 'sys' is not defined

    but I also now just tried exit() on it's own and it worked :)

    Thanks for the help! I know it was a small error to fix, but it'ts cool to me that it now works the way I want it to. I can now move on content that I achieved what I wanted to. :P

    Plus I may just come back and keep adding onto it as I go.

    • tefids
      +2

      Sounds like you got it working, but if you are curious as to why "sys.exit()" doesn't work, it sounds like you haven't imported the sys module. To do this simply place "import sys" at the top of the file. Hope this helps.

      • Wenjarich
        +3

        Oh I see, thanks :)

        • redalastor
          +2

          You pretty much always need to import things first : https://xkcd.com/353/ :D

        • Wenjarich
          +2
          @redalastor -

          I'm extremely tempted to try typing import antigravity into my code now :D

        • redalastor
          +3
          @Wenjarich -

          Actually, do try it. It links you to that comic.

          Also try

          import this
          
        • jmcs
          +1
          @redalastor -

          That should be in every tutorial even before the hello world.

        • redalastor
          +2
          @jmcs -

          Tutorials are often lacking. For instance, none seems to deal virtual environments, one of the most important concepts of python.

        • jmcs
          +1
          @redalastor -

          That's probably because before python 3.3 virtual environments were a third party solution and not part of the standard library. When we finally get good python 3 tutorials maybe they'll include venv.