Python __future__在特定模块之外

Loï*_*ier 5 python matplotlib

在python 2.7中,通过使用

 from __future__ import division, print_function
Run Code Online (Sandbox Code Playgroud)

我现在可以print(1/2)展示了 0.5.

但是有可能在python启动时自动导入吗?

我试图使用sitecustomize.py特殊模块,但inport仅在模块内部有效,而不在shell中.

我相信人们会问为什么我需要这个:向青少年教授Python我注意到整数划分对他们来说并不容易,所以我们决定切换到Python 3.然而,课程的要求之一就是能够plot函数和Matplotlib非常好,但仅对Python 2.7有效.

所以我的想法是使用自定义2.7安装...不完美但我没有更好的想法让Matplotlib和新的"自然"分区"1/2 = 0.5".

任何建议或者可能是在python 3.2上运行的Matplotlib替代方案?

DSM*_*DSM 6

python 3上的matplotlib比你想象的更接近:https://github.com/matplotlib/matplotlib-py3 ; http://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib.

为什么不使用PYTHONSTARTUP而不是sitecustomize.py?

localhost-2:~ $ cat startup.py 
from __future__ import print_function
from __future__ import division
localhost-2:~ $ export PYTHONSTARTUP=""
localhost-2:~ $ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>> print("fred",end=",")
  File "<stdin>", line 1
    print("fred",end=",")
                    ^
SyntaxError: invalid syntax
>>> ^D
localhost-2:~ $ export PYTHONSTARTUP=startup.py
localhost-2:~ $ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>> print("fred",end=",")
fred,>>> 
Run Code Online (Sandbox Code Playgroud)