[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: importing modules at IDLE strartup



Hi,
first of all sorry for writing my first post in french. Hereafter is the
english version of my text:

I'm using python (version 2.5.2, under debian lenny for personnal use on
my notebook, and  version 2.6 under Windows XP with my students) for
teaching an introduction to algorithmic at High School (in France). I'm
also using IDLE as IDE.
Here is my problem (I try to solve it under linux fisrt):

1) I wrote a .pythonrc.py file with the two lines

from __future__ import division
from math import *

2) in my .bashrc file I wrote

PYTHONSTARTUP = "/home/fred/.pythonrc.py"
export PYTHONSTARTUP

3) when invoking python interactively in a terminal, it works fine:

>>> 1/3
0.33333333333333331
>>> sqrt(5)
2.2360679774997898

4) I wrote a small script file test.py which contains

print sqrt(2)
print 1/3

Editing/testing this file with IDLE with the following command line:

idle-python2.5 -n -s test.py

and executing it with F5 gives the lines

IDLE 1.2.2      ==== No Subprocess ====
>>> 
>>> 
1.41421356237
0

So I have here a first problem with 1/3 division that should give a
float result (according to the startup file import from __future__).

5) More annoying yet, when launching IDLE through the menu (under
gnome), even the sqrt(2) command is not accepted (NameError: name 'sqrt'
is not defined). I have checked that IDLE is launched with the
command /usr/bin/idle-python2.5 -n -s

Does anyone know how to solve this ? (of course I know that I could
write 1.0/3, or also I could migrate to python 3).  I simply want to
"simplify" the python syntax for my students, so that "/" operator is
always for them the usual (float) division, and usual math functions are
available, this WITHOUT having to write any import at the top of their
script. I also know that such scripts could easily be broken when
changing the environment. This is not indeed a problem for me, since I'm
not here teaching how to produce good programs.

Thank's in advance for any valuable help.
    Frederic.




Reply to: