#1
  1. No Profile Picture
    James
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Beer Sheva, Israel
    Posts
    12
    Rep 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.....
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    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.
  4. #3
  5. No Profile Picture
    James
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Beer Sheva, Israel
    Posts
    12
    Rep 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.
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    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.
  8. #5
  9. No Profile Picture
    James
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Beer Sheva, Israel
    Posts
    12
    Rep 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...
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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
  12. #7
  13. No Profile Picture
    James
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Beer Sheva, Israel
    Posts
    12
    Rep Power
    0
    Ahhh, things are beginning to clear up even more.

    I certainly do thank the both of you.

    Now, watch my smoke....(puff)

IMN logo majestic logo threadwatch logo seochat tools logo