The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Real time vs script commands
Discuss Real time vs script commands in the Python Programming forum on Dev Shed. Real time vs script commands Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 2nd, 2004, 04:20 AM
|
|
James
|
|
Join Date: Apr 2004
Location: Beer Sheva, Israel
Posts: 12
Time spent in forums: 27 m 27 sec
Reputation Power: 0
|
|
|
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, 05:49 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
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. 
|

April 2nd, 2004, 06:59 AM
|
|
James
|
|
Join Date: Apr 2004
Location: Beer Sheva, Israel
Posts: 12
Time spent in forums: 27 m 27 sec
Reputation Power: 0
|
|
|
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.
|

April 2nd, 2004, 09:35 AM
|
 |
Mini me.
|
|
Join Date: Nov 2003
Location: Cambridge, UK
|
|
|
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.
|

April 2nd, 2004, 10:31 AM
|
|
James
|
|
Join Date: Apr 2004
Location: Beer Sheva, Israel
Posts: 12
Time spent in forums: 27 m 27 sec
Reputation Power: 0
|
|
|
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, 11:40 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
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
|

April 2nd, 2004, 02:04 PM
|
|
James
|
|
Join Date: Apr 2004
Location: Beer Sheva, Israel
Posts: 12
Time spent in forums: 27 m 27 sec
Reputation Power: 0
|
|
Ahhh, things are beginning to clear up even more.
I certainly do thank the both of you.
Now, watch my smoke.... (puff) 
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|