April 2nd, 2004, 05:20 AM
Real time vs script commands
I am just getting started with Python and so far it is very good.
Since this is a forum, I am supposed to ask a question, right?
Okay, here it is. How can I tell which commands are for real time only (IDLE), and which ones are for scripts?
Okay, there it is.
Have a nice day.....
April 2nd, 2004, 06:49 AM
The only thing I know that is specific to IDLE is
_ which always contains the last result calculated and the evaluation of expressions like 1+1 without assignment to a name. Everything else that you can do on the interactive console you can include in your programs.
I am guessing you don't mean IDLE editing commands like Alt-P, CTRL-X, F5 etc.
April 2nd, 2004, 07:59 AM
Thanks for the reply....
Here is an example of what I am talking about.....
In a script, I write:
The only outpt is from the print testlist command.
The len(testlist) doesn't produce anything.
The same code written in real time (IDLE) produces both the print as well as the len command.
Which makes me wonder how I'm supposed to differentiate between the cans and cannots.
April 2nd, 2004, 10:35 AM
The interactive console is special - expressions are always evaluated for printing on the screen. So when you type len(something) it prints the result. You could call this a "side-effect" of using the interactive console. It makes your life easier for testing out code.
In a program you don't want "side-effects". You only get things printed if you explicitly use the print command.
In a program having the expressions
on there own line is pointless because nothing happens to the result.
April 2nd, 2004, 11:31 AM
All right.... I appreciate your response.
I think I understand what you are saying, as it makes a lot of sense. Again, thanks a lot...
April 2nd, 2004, 12:40 PM
One other point that Grim didn't mention. If you enter a line in the interactive shell that returns None, then it is not printed. This may be what confused you in the first place. Functions that do not explicitly return a value always return None.
The import statement and chdir do not have a return value, so nothing is printed.
>>> import os
Dave - The Developers' Coach
April 2nd, 2004, 03:04 PM
Ahhh, things are beginning to clear up even more.
I certainly do thank the both of you.
Now, watch my smoke....(puff)