On Tue, May 6, 2008 at 11:40 AM, Dick Moores <[EMAIL PROTECTED]> wrote:
>
>
>
>
> At 09:07 AM 5/6/2008, Kent Johnson wrote:
>
> You can right-justify in a format operation. You will have to do it in
> two steps since the string you want to right-justify is itself the
> result of a format operation:
> line2 = "Or %d weeks and %d days" % (weeks, days2)
> print '%50s' % line2
>
> Instead of 50 you probably want to use the length of the previous
> line. You can insert this into the format using * for the length:
> print %*s' % (len(line1), line2)
> print "This is a very very long line ending in %s" % "even more length"
> print "A short %s" % "line"
I think it would consist of
line1 = "This is a very very long line ending in %s" % "even more length"
line2 = "A short %s" % "line"
print line1
print '%*s' % (len(line1), line2)
In a function:
>>> def foo(string1, string2):
... print string1
... print '%*s' % (len(line1), line2)
...
>>> foo(line1, line2)
This is a very very long line ending in even more length
A short line
(as close as I can get it with non-monospace)
-Wayne
>>> def foo2(line1, line2):
print line1
print '%*s' % (len(line1), line2)
>>> line1 = "This is a very very long line ending in %s" % "even more length"
>>> line2 = "A short %s" % "line"
>>> foo2(line1, line2)
This is a very very long line ending in even more length
A short line
>>>
Is that what you meant?
I'm afraid I still don't understand what to do to change my printResult().
def printResult(date1, date2, days1, weeks, days2):
print "\nThe difference between %s and %s is %d days" % (date1.strftime("%m/%d/%Y"),
date2.strftime("%m/%d/%Y"), days1)
print 37 * " ",
print "Or %d weeks and %d days" % (weeks, days2)
print ((len(str(weeks)) + len(str(days2))) + 57) * "="
Could someone just come right out and do it for me? I'm lost here. That '*' is just too magical.. Where did you guys learn about '%*s'? Does the '%s' still mean a string?
Dick
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor