About 49,900 results
Open links in new tab
  1. What is the best way to exit a function (which has no return value) …

    return None or return can be used to exit out of a function or program, both does the same thing; quit() function can be used, although use of this function is discouraged for making real world applications and should be used only in interpreter.

  2. python - How to stop a function - Stack Overflow

    A simple return statement will 'stop' or return the function; in precise terms, it 'returns' function execution to the point at which the function was called - the function is terminated without further action. That means you could have a number of places throughout your function where it might return. Like this:

  3. python - How do I terminate a script? - Stack Overflow

    Sep 16, 2008 · (Note: using exceptions for exits is a python practical work-around for C/C++/Java devs always inappropriately calling exit-- hence python programmers may not notice the stench of this code smell as much); and lastly, (3) multi-threaded code (which pythonistas have historically just …

  4. Python exit commands - why so many and when should each be …

    Nov 3, 2013 · After all, one of the most likely things a newbie will try to exit Python is typing in quit. Nevertheless, quit should not be used in production code. This is because it only works if the site module is loaded. Instead, this function should only be used in the interpreter. exit() is an alias for quit (or vice-versa). They exist together simply ...

  5. How to properly quit a program in python - Stack Overflow

    Oct 23, 2012 · Now Quit will be whatever the user typed in, so let's check for "Q" instead of True: if Quit == "Q": Instead of sys.exit(0), you can probably just end your while look with break or just return if you're in a function. Also, I don't recommend the name "Quit" for a variable that just stores user input, since it will end up confusing.

  6. Quit function in python program - Stack Overflow

    Jul 12, 2012 · I want people to be able to quit from the main menu, or by a particular key-press in-game (say, Shift+Q). I'm running it, for now, in Windows, though I am working on compiling Linux/Mac versions. Pressing the X button works if there's no 'while' loop running, it seems, and that closes it correctly, otherwise it seems to 'store' the close ...

  7. How do I abort the execution of a Python script? [duplicate]

    Jan 26, 2010 · done = True if done: # quit/stop/exit else: # do other stuff Essentially, I am looking for something that behaves equivalently to the 'return' keyword in the body of a function which allows the flow of the code to exit the function and not execute the remaining code.

  8. How to quit Python function, throwing error statement without …

    Perhaps out of ignorance (I see many beginners just doing except:), perhaps because they really want to catch all exception out of some misguided sense of "reliability" (sometimes seen in intermediate programmers), perhaps because catching (almost) all exceptions really is the correct thing to do at this point, e.g. you're running arbitrary code (e.g. a hook) and need to be robust …

  9. python - Proper way to quit/exit a PyQt program - Stack Overflow

    Calling QCoreApplication.quit() is the same as calling QCoreApplication.exit(0). To quote from the qt docs: After this function has been called, the application leaves the main event loop and returns from the call to exec(). The exec() function returns returnCode. If the event loop is not running, this function does nothing. [emphasis added]

  10. difference between quit and exit in python - Stack Overflow

    Oct 10, 2013 · 1) When I use help() and type() function for each one, it says that both are object of class Quitter, which is defined in the module site. 2) When I use id() to check the addresses of each one, it returns different addresses i.e. these are two different objects of …