|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
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..... ![]() |
|
#2
|
||||
|
||||
|
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. Console only: Code:
>>> 8+2 10 >>> _ 10 >>> I am guessing you don't mean IDLE editing commands like Alt-P, CTRL-X, F5 etc. ![]()
__________________
*** Experimental Python Markup CGI V2 *** |
|
#3
|
|||
|
|||
|
Thanks for the reply....
Here is an example of what I am talking about..... In a script, I write: testlist =("one","two","three","four","five") print testlist len(testlist) 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. |
|
#4
|
||||
|
||||
|
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 1+1 len(something) on there own line is pointless because nothing happens to the result. |
|
#5
|
|||
|
|||
|
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... |
|
#6
|
|||
|
|||
|
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.
e.g. Code:
>>>
>>> 123
123
>>> None
>>> import os
>>> os.getcwd()
'C:\\dev\\Python23\\lib\\site-packages'
>>> os.chdir('C:/')
>>>
The import statement and chdir do not have a return value, so nothing is printed. Dave - The Developers' Coach |
|
#7
|
|||
|
|||
|
Ahhh, things are beginning to clear up even more.
I certainly do thank the both of you. Now, watch my smoke....(puff) ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Real time vs script commands |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|