[Tutor] Running Python in script vs. Idle
Steven D'Aprano
steve at pearwood.info
Mon Jul 25 01:59:35 CEST 2011
brandon w wrote:
> Thank you. I understand that this ( x = 1+2 ) assigns a variable to "x"
> and will not print in Idle, but how would I get the 'class' that I
> created to run from the script like it does in Idle? Will I have to put
> print before everything I have to print?
Yes. If you want something printed, you have to print it.
In your script, you have:
# definition of ExClass not shown
x = ExClass()
x.eyes
x.age
x.height
x.thisMethod()
print x.thisMethod()
This creates an instance of ExClass, calls it "x". Then it retrieves the
eyes, age and height from x, but does nothing with the results except
immediately discard them. Then it calls thisMethod, and discards the
result. Lastly, it calls thisMethod again and prints the result. That is
the only thing that the script will output.
I recommend you do this instead:
# definition of ExClass not shown
x = ExClass()
print x.eyes, x.age, x.height
print x.thisMethod()
--
Steven
More information about the Tutor
mailing list