About IDLE?

Discussion in 'Python' started by Dr. Pastor, Mar 9, 2006.

  1. Dr. Pastor

    Dr. Pastor Guest

    Installed Python 2.4.2 on Windows XP.
    Activated IDLE.
    Loaded the following into the Edit window:
    ---
    # dates are easily constructed and formatted (Tutorial 10.8)

    from datetime import date
    now = date.today()
    now

    now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")

    # dates support calendar arithmetic

    birthday = date(1985, 12, 1)
    age = now - birthday
    age.days
    ---
    When I select Run Module in the Edit window, I got only
    two >>> after the RESTART line.
    I expected to see the output of several commands!
    Typing in age.days do produce the number of days.

    Why I do not get any output?
    Thanks for any guidance.
    Dr. Pastor, Mar 9, 2006
    #1
    1. Advertising

  2. Dr. Pastor enlightened us with:
    > When I select Run Module in the Edit window, I got only
    > two >>> after the RESTART line.
    > I expected to see the output of several commands!


    You never gave it any commands that print output.

    I suggest reading the Python tutorial.

    Sybren
    --
    The problem with the world is stupidity. Not saying there should be a
    capital punishment for stupidity, but why don't we just take the
    safety labels off of everything and let the problem solve itself?
    Frank Zappa
    Sybren Stuvel, Mar 9, 2006
    #2
    1. Advertising

  3. "Dr. Pastor" wrote:

    > Installed Python 2.4.2 on Windows XP.
    > Activated IDLE.
    > Loaded the following into the Edit window:
    > ---
    > # dates are easily constructed and formatted (Tutorial 10.8)
    >
    > from datetime import date
    > now = date.today()
    > now
    >
    > now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
    >
    > # dates support calendar arithmetic
    >
    > birthday = date(1985, 12, 1)
    > age = now - birthday
    > age.days
    > ---
    > When I select Run Module in the Edit window, I got only
    > two >>> after the RESTART line.
    > I expected to see the output of several commands!
    > Typing in age.days do produce the number of days.
    >
    > Why I do not get any output?


    while the interactive console echoes the result back if you type in an
    arbitrary expression, the interpreter doesn't do that if you run things in
    a script.

    to print stuff from a script, use the "print" statement.

    print now
    print now.strftime(...)
    ...
    print age.days

    your favourite tutorial (hopefully) contains more information about the
    interactive mode, and how it differs from code in scripts or modules.

    hope this helps!

    </F>
    Fredrik Lundh, Mar 9, 2006
    #3
  4. Sybren Stuvel wrote:
    > Dr. Pastor enlightened us with:
    > > When I select Run Module in the Edit window, I got only
    > > two >>> after the RESTART line.
    > > I expected to see the output of several commands!

    >
    > You never gave it any commands that print output.
    >
    > I suggest reading the Python tutorial.
    >


    To be more specific, when you type in an expression at the Python
    prompt, it will evaluate it and then print it (if it doesn't evaluate
    to None). In a module it doesn't do that, as then you'd have all sorts
    of things printed out modules were imported.
    Nick Smallbone, Mar 9, 2006
    #4
  5. Dr. Pastor

    Dr. Pastor Guest

    Any reply?

    Dr. Pastor wrote:
    > Installed Python 2.4.2 on Windows XP.
    > Activated IDLE.
    > Loaded the following into the Edit window:
    > ---
    > # dates are easily constructed and formatted (Tutorial 10.8)
    >
    > from datetime import date
    > now = date.today()
    > now
    >
    > now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.")
    >
    > # dates support calendar arithmetic
    >
    > birthday = date(1985, 12, 1)
    > age = now - birthday
    > age.days
    > ---
    > When I select Run Module in the Edit window, I got only
    > two >>> after the RESTART line.
    > I expected to see the output of several commands!
    > Typing in age.days do produce the number of days.
    >
    > Why I do not get any output?
    > Thanks for any guidance.
    >
    >
    Dr. Pastor, Mar 9, 2006
    #5
  6. Nick Smallbone, Mar 10, 2006
    #6
  7. Dr. Pastor

    Terry Reedy Guest

    "Dr. Pastor" <> wrote in message
    news:zs_Pf.4292$...
    > Installed Python 2.4.2 on Windows XP.
    > Activated IDLE.
    > Loaded the following into the Edit window:


    > Why I do not get any output?
    > Thanks for any guidance.


    When you run code from an edit window, IDLE saves the file to disk and then
    *imports* it into the shell window. If you *paste* code into the shell
    window (regardless of where from), then it acts like you typed it and you
    will get expression results echoed, as you expected.

    I got caught be this at first too, since I have run many snippets by
    pasting.

    Terry Jan Reedy
    Terry Reedy, Mar 10, 2006
    #7
  8. Dr. Pastor

    Dr. Pastor Guest

    Dr. Pastor, Mar 10, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Owen

    Idle time updates

    Jim Owen, Jul 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    311
    Natty Gur
    Jul 3, 2003
  2. Jim
    Replies:
    2
    Views:
    412
    bruce barker
    Jul 19, 2004
  3. Shikari Shambu
    Replies:
    1
    Views:
    748
    Scott G.
    Aug 6, 2004
  4. Gordon Smith
    Replies:
    1
    Views:
    3,541
    Curt_C [MVP]
    Mar 1, 2005
  5. Starwynd
    Replies:
    1
    Views:
    387
    Tor Iver Wilhelmsen
    Nov 23, 2003
Loading...

Share This Page