[Python-Dev] IDLE reading IDLESTARTUP or PYTHONSTARTUP on restart

Mitchell L Model MLMLists at Comcast.net
Sat Feb 7 20:09:18 CET 2009


I have a small change (shown below) to PyShell.py in idlelib that 
causes the subprocess interpreter to read IDLESTARTUP or 
PYTHONSTARTUP each time it restarts. To me this would make IDLE much 
more useful for myself and students I teach.  It isn't quite clear 
what behavior to install with the enabling patch, so I would like 
some feedback before submitting it. The main question is:

Shouldn't IDLE always read IDLESTARTUP (if defined) or PYTHONSTARTUP 
(if IDLESTARTUP is not defined and PYTHONSTARTUP is) when it starts 
rather than that requiring a command-line switch as it does now? This 
is the behavior of python, and I don't see why it should be any 
different for IDLE. More importantly, there is no convenient way to 
say "and read my startup file" when double-clicking the IDLE icon. 
(I'm on a Mac. On Windows the -s switch could be added to an icon for 
IDLE, but that's still awkward.)

Secondary questions;

If IDLE is changed to read a startup file, should the -s switch be 
dropped altogether? If so, should a -q switch be added (as with 
emacs) to start without loading the startup file? I think yes to both.

When the subprocess interpreter is restarted should it look in the 
environment for the current values of IDLESTARTUP and PYTHONSTARTUP, 
or should IDLE store those values in a property of the subprocess 
interpreter when first started and have restart go directly to the 
saved path even if the value of IDLESTARTUP or PYTHONSTARTUP has 
changed since IDLE had been started. I think restart should go to the 
path as it was when IDLE was started and ignore subsequent changes. 
Or at least the reststart should notice the change and present a 
dialog asking the user to choose between the old path and the new one.


The diff modifies PyShell by copying the four lines of code that load 
IDLESTARTUP or PYTHONSTARTUP from where they appear in the initial 
startup code and adding to where the subprocess interpreter writes 
"RESTART" to the console.

@@ -434,6 +434,10 @@
          console.write(halfbar + ' RESTART ' + halfbar)
          console.text.mark_set("restart", "end-1c")
          console.text.mark_gravity("restart", "left")
+        filename = os.environ.get("IDLESTARTUP") or \
+                   os.environ.get("PYTHONSTARTUP")
+        if filename and os.path.isfile(filename):
+            self.execfile(filename)
          console.showprompt()
          # restart subprocess debugger
          if debug:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20090207/c8985725/attachment.htm>


More information about the Python-Dev mailing list