[Tutor] Running Python in script vs. Idle
Steven D'Aprano
steve at pearwood.info
Mon Jul 25 01:28:19 CEST 2011
brandon w wrote:
> I wrote this in Idle and ran it in Idle and it worked fine.
[...]
> Then I try to run it from a script in Gnome-terminal and it does not
> run. I do not get output. I have to add print. to get any output like this:
[...]
> What is the difference? This is what was confusing me before.
As a convenience, the Python interactive interpreter prints the output
of any line you give it. So a line like this:
x = 1+2
doesn't print anything, because the result is stored as x. But a line
like this:
1+2
prints 3. This is *purely* a convenience feature, and it is only
activated in the *interactive* interpreter. When running as a script,
you need to explicitly call print to have things printed.
IDLE emulates that behaviour.
--
Steven
More information about the Tutor
mailing list