How can I use __future__ separation in IDLE startup file

In Python 2.7, how can I use an IDLE application \__future__ division

without from \__future__ import division

manual input every time I start IDLE?

If I put from \__future__ import division

at the top of my .idlestartup file, it gets ignored even if other things in .idlestartup are done. For example:

~> cat >.idlestartup
from __future__ import division
print("Executing .idlestartup")
~> idle -s

      

This is what my IDLE window looks like after I try to split:

Python 2.7.8 |Anaconda 2.1.0 (x86_64)| (default, Aug 21 2014, 15:21:46) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> 
Executing .idlestartup
>>> 2/3
0
>>>

      

I am using Mac OS X 10.9.5 Mavericks (also had the same problem in earlier versions of OS X). Note that the above command line version has been included to make it easier to display what I am saying, but I am more interested in the version that launches the IDLE application from the GUI.

The solution suggested by Ashwini Chaudhary below worked for launching the Anaconda version from the command line, but not for launching the IDLE application.

I was finally able to get the future unit running automatically in an IDLE application by adding "sys.argv.insert (1, '-Qnew") to /Applications/IDLE.app/Contents/MacOS/IDLE. Both Ashwini Chaudhary's solutions below seem fragile. I wonder if there is a cleaner way.

+3


source to share


1 answer


Adding the instruction __future__

at the top /usr/lib/python2.7/idlelib/PyShell.py

did the job for me.

I'm on Ubuntu, the path may be different for other OS:



>>> import idlelib
>>> idlelib.PyShell.__file__
'/usr/lib/python2.7/idlelib/PyShell.py'

      

+2


source







All Articles