[Tutor] Print text position problems when using triple quotes
Luke Jordan
luke.jordan at gmail.com
Thu Feb 24 19:57:24 CET 2005
Execllent.
Many Thanks,
Luke
On Thu, 24 Feb 2005 13:15:41 -0500, Bill Mill <bill.mill at gmail.com> wrote:
> On Thu, 24 Feb 2005 13:14:13 -0500, Bill Mill <bill.mill at gmail.com> wrote:
> > On Thu, 24 Feb 2005 10:02:44 -0800, Luke Jordan <luke.jordan at gmail.com> wrote:
> > > 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?
> >
> > Why not just take them out of the block, and either make them global
> > to the module or create a string module? i.e.:
> >
> > prompt1 = """This is a long string with %s string variables
> > %s scattered all over the place
> > as well as odd indentation %s
> > and funny lines
> > ------------------
> > ============"""
> >
> > class foo:
> > def bar(self):
>
> Sorry, I forgot that if it's in the module, you should declare prompt1
> as global by using "global prompt1" right here.
>
> > print prompt1 % (var1, var2, var3)
> >
> > peace
> > Bill Mill
> > bill.mill at gmail.com
> >
>
--
"If you think that was good, wait 'til you taste the antidote!"
More information about the Tutor
mailing list