How do I import from __future__ at startup?
Hello all, I managed to do this once, but I forgot. 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? Is there any way at all? I searched google and python.org but didn't find a quick answer to this. Perhaps somebody can help me out? Thanks, Christian
[ Christian Mascher <christian.mascher@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___(|_|] -----------------------------------------------
One way to accomplish this is to start Python with the -Qnew switch: python -Qnew If you want to run a script with this option, e.g. the script division.py with this content: print 11/3 then use c:\Python24\python -Qnew division.py 3.6666666667 (or something similar on a Linux system) Regards, Gregor Christian Mascher schrieb:
Hello all,
I managed to do this once, but I forgot.
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? Is there any way at all?
I searched google and python.org but didn't find a quick answer to this. Perhaps somebody can help me out?
Thanks,
Christian
_______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
-- Gregor Lingl Reisnerstrasse 3/19 A-1030 Wien Telefon: +43 1 713 33 98 Mobil: +43 664 140 35 27 Autor von "Python für Kids" Website: python4kids.net
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? Is there any way at all?
I searched google and python.org but didn't find a quick answer to this. Perhaps somebody can help me out?
$ python -Qnew Python 2.3.4 (#2, Aug 6 2004, 10:37:58) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
1/2 0.5
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
Hi I joined the list to demonstrate the wonderful benefits of such a list to our organisation, but I don't know how to unsubscribe. HELP!!! Ken :o) ----- Original Message ----- From: "Guido van Rossum" <gvanrossum@gmail.com> To: "Christian Mascher" <christian.mascher@gmx.de> Cc: <edu-sig@python.org> Sent: Monday, February 28, 2005 9:59 AM Subject: Re: [Edu-sig] How do I import from __future__ at startup?
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? Is there any way at all?
I searched google and python.org but didn't find a quick answer to this. Perhaps somebody can help me out?
$ python -Qnew Python 2.3.4 (#2, Aug 6 2004, 10:37:58) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
1/2 0.5
-- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ Edu-sig mailing list Edu-sig@python.org http://mail.python.org/mailman/listinfo/edu-sig
participants (5)
-
Christian Mascher
-
Gregor Lingl
-
Guido van Rossum
-
Ken Dobson
-
Rodrigo Dias Arruda Senra