[Edu-sig] How do I import from __future__ at startup?
Rodrigo Dias Arruda Senra
rsenra at acm.org
Sun Feb 27 12:40:04 CET 2005
[ Christian Mascher <christian.mascher at gmx.de> ]
-----------------------------------------------
| I want division always to be imported from __future__ at startup.
| Putting
| from __future__ import division
| in a file sitecustomize.py doesn't work (which I think is
| counterintuitive). Do I have to use PYTHONSTARTUP variable?
That certainly works for the interactive prompt, as follows:
$ cat z.py
from __future__ import division
$ export PYTHONSTARTUP=/home/rodrigo/z.py
$ python
Python 2.4 (#1, Dec 1 2004, 00:03:22)
[GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 2/3
0.66666666666666663
But that not holds for script execution.
$ cat z2.py
print 2/3
$ python z2.py
0
As documented in the tutorial:
"""
2.2.4 The Interactive Startup File
When you use Python interactively, it is frequently handy to have some standard
commands executed every time the interpreter is started. You can do this by setting
an environment variable named PYTHONSTARTUP to the name of a file containing your
start-up commands. This is similar to the .profile feature of the Unix shells.
This file is only read in interactive sessions, not when Python reads commands
from a script, and not when /dev/tty is given as the explicit source of commands
(which otherwise behaves like an interactive session). It is executed in the same
namespace where interactive commands are executed, so that objects that it defines
or imports can be used without qualification in the interactive session. You can also
change the prompts sys.ps1 and sys.ps2 in this file.
"""
hth,
| Is there any way at all?
Do you mean any other way ?
best regards,
Senra
--
,_
| ) Rodrigo Senra <rsenra |at| acm.org>
|(______ -----------------------------------------------
_( (|__|] GPr Sistemas http://www.gpr.com.br
_ | (|___|] IC - Unicamp http://www.ic.unicamp.br/~921234
___ (|__|]
L___(|_|] -----------------------------------------------
More information about the Edu-sig
mailing list