![]() In theory, you can even assign raw_input instead of real_raw_input but there might be modules that check existence of raw_input and behave accordingly. Using raw input is usually time expensive (waiting for input), so it's not important. It's quite expensive but short and readable. Real_raw_input = vars(_builtins_).get('raw_input',input) Here's a piece of code I put in my scripts that I wan't to run in py2/3-agnostic environment: # Thank you, python2-3 team, for making such a fantastic mess with Timmerman's solution works great when running the code, but if you don't want to get Undefined name errors when using pyflakes or a similar linter you could use the following instead: try: Your program will run in a window that stays open after your program ends, and in which you can enter Python commands to run immediately. ![]() When your program appears in the editor, press F5 or choose "Run module" from the "Run" menu. Among other features it can run your programs in a window. IDLE is a simple program editor that comes installed with Python. If you want to run your program again, you can press the up arrow to recall the previous command you entered and press enter to run it again, rather than having to type out the file name every time. (If you get an error that "python" is not a recognized command, see ) When your program finishes running, whether it completes successfully or not, the window will remain open and the command-prompt will appear again for you to type another command. To run your program, type the following (substituting your script name): python myscript.py (I think this works on Windows Vista and Windows 7.) This will open a command-prompt window that looks something like this: Microsoft Windows Ĭopyright (c) 2009 Microsoft Corporation. The menu that pops up should contain an entry "Open command window here". When you're looking at the folder window that contains your Python program, hold down shift and right-click anywhere in the white background area of the window. You might find it easier to use a command-prompt or IDLE. However, as you've seen, if something goes wrong, such as an error in your program, that statement won't be executed and the window will close without you being able to see what went wrong. To solve this, your book recommends adding a raw_input / input statement to wait until the user presses enter. The terminal window that pops up closes as soon as your program ends, so you can't see what the result of your program was. py file and then you're double-clicking on it to run it. Six is a module which patches over many of the 2/3 common code base pain points.Īs others have indicated, the raw_input function has been renamed to input in Python 3.0, and you really would be better served by a more up-to-date book, but I want to point out that there are better ways to see the output of your script.įrom your description, I think you're using Windows, you've saved a. This works in Python 3.x and 2.x: # Fix Python 2.x.Ī reliable way to address this is from six.moves import input ![]() Starting with Python 3, raw_input() was renamed to input().įrom What’s New In Python 3.0, Builtins section second item.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |