[Tutor] Running Python in script vs. Idle

brandon w thisisonlyatest at gmx.com
Mon Jul 25 02:10:54 CEST 2011


On 07/24/2011 07:59 PM, Steven D'Aprano wrote:
> 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()
>
>
>
>
Thanks. I understand now.


More information about the Tutor mailing list