[Tutor] IDLE shell indentation?

eryksun eryksun at gmail.com
Fri Oct 19 04:46:02 CEST 2012


On Thu, Oct 18, 2012 at 10:11 PM, boB Stepp <robertvstepp at gmail.com> wrote:
>>>> if zero:
>         print(zero)
> else:
>         print(phrase)
>
> Is there some special way for typing in multiline blocks of code into
> the shell in IDLE? The above works, but it bothers me that "else" does
> not line up with "if". Also, in the IDLE shell the "p" in "print"
> actually lines up under the "e" in "zero". However when I copied from
> IDLE and pasted into gmail, this alignment was changed. I am guessing
> it is because gmail is not using a fixed-width font. And I have yet to
> figure out how to get it to use one when in plaintext mode.

You're right that the alignment changed because of the font rendering
of the tab character. In Firefox I use the following to get a
monospace font in Gmail:

http://userstyles.org/styles/15618/gmail-monospace-font-for-body-messages-textarea

As to your main question, I use exec:

    >>> zero, phrase = '', 'spam'
    >>> exec('''
    if zero:
        print(zero)
    else:
        print(phrase)
    ''')
    spam


More information about the Tutor mailing list