[Tutor] Print text position problems when using triple quotes

Luke Jordan luke.jordan at gmail.com
Thu Feb 24 19:02:44 CET 2005


Hi all,

I've tried a lot of experimenting and searching through various
tutorials, and I haven't been able to come up with a solution to this,
ostensibly simple, problem.

I'm writing a simple game (run in command line) in which narrative
text is printed in response to a user's decisions. The problem I'm
running into is that triple quotes used in an indented block preserves
the indentation when it prints. I'm writing code like this:

if userInput == 1:
        some stuff
        print """
texttexttexttexttexttexttexttext
        """
        question within a question
        if userInput == 1:
                print """
texttexttexttexttexttexttexttext
texttexttexttexttexttexttexttext
                """
        elif userInput == 2:
                print """
owowowowowowowowowowow
                """

to preserve the text's position at left when I run it in the
command-line. The blocks get distorted and it becomes painful to read.

Is there a way to preserve the readability of the code and have
printed text from indented blocks, say, nested conditionals, appear
flush at left, not printed exactly where I've written them in the
script?

I know I can accomplish this using single quotes instead of triple
quotes, but I'm holding out hope that I can avoid putting each
sentence in a separate print statement.

if userInput == 1:
        print "here's 80 characters"
        print "now another 80"
        etc.

Also, I've tried string.ljust(), but either I'm doing it wrong or it
isn't the trick I'm looking for.

Thanks for the help.

Luke
-- 
"If you think that was good, wait 'til you taste the antidote!"


More information about the Tutor mailing list