12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• You must add “.py” explicitly when saving your files. I mentioned this whentalking about files in general, but it’s a common IDLE stumbling block, especiallyfor Windows users. IDLE does not automatically add a .py extension tofilenames when files are saved. Be careful to type the .py extension yourself whensaving a file for the first time. If you don’t, you will be able to run your file fromIDLE (and system command lines), but you will not be able to import your fileeither interactively or from other modules.• Run scripts by selecting Run ➝ Run Module in text edit windows, not by interactiveimports and reloads. Earlier in this chapter, we saw that it’s possible torun a file by importing it interactively. However, this scheme can grow complexbecause you are required to manually reload files after changes. By contrast,using the Run ➝ Run Module menu option in IDLE always runs the most currentversion of your file. It also prompts you to save it first, if needed (anothercommon mistake outside IDLE).• You may still have to reload nested modules. Technically speaking, IDLE’s Run➝ Run Module menu option always runs the current version of the top-level fileonly; imported files may still need to be interactively reloaded when changed. Ingeneral, though, Run ➝ Run Module eliminates common confusions surroundingimports. If you choose to use the import and reload technique instead,remember to use Alt-P/Alt-N key combinations to recall prior commands.• You can customize IDLE. To change the text fonts and colors in IDLE, select theConfigure option in the Options menu of any IDLE window. You can also customizekey combination actions, indentation settings, and more; see IDLE’sHelp pull-down menu for more hints.• There is currently no clear-screen option in IDLE. This seems to be a frequentrequest (perhaps because it’s an option available in similar IDEs), and it mightbe added eventually. Today, though, there is no way to clear the interactive window’stext. If you want the window’s text to go away, you can either press andhold the Enter key, or type a <strong>Python</strong> loop to print a series of blank lines.• Tkinter GUI and threaded programs may not work well with IDLE. BecauseIDLE is a <strong>Python</strong>/Tkinter program, it can hang if you use it to run certain typesof advanced <strong>Python</strong>/Tkinter programs. This has become less of an issue in morerecent versions of IDLE that run user code in one process, and the IDLE GUIitself in another, but some programs may still hang the GUI. Your code may notexhibit such problems, but, as a rule of thumb, it’s always safe if you use IDLEto edit GUI programs, but launch them using other options, such as icon clicksor system command lines. When in doubt, if your code fails in IDLE, try it outsidethe GUI.• If connection errors arise, try starting IDLE in single-process mode. BecauseIDLE requires communication between its separate user and GUI processes, itcan sometimes have trouble starting up on certain platforms (notably, it fails toThe IDLE User Interface | 53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!