Re: [Tutor] String Replacement question

2008-05-22 Thread Faheem
Hey All, Thanks.. That was quick. Good to know there is a mailing list like this one. Thanks to everyone and all the replies. Faheem ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] String Replacement question

2008-05-22 Thread wesley chun
> > some = 'thing' > > print '%s %s %s %s' % (some,some,some,some) > > You can use named parameters, which moves the repetition to the format string: > > In [24]: print '%(some)s %(some)s %(some)s %(some)s' % (dict(some=some)) > thing thing thing thing > > With multiple values, a common trick

Re: [Tutor] String Replacement question

2008-05-22 Thread Ricardo Aráoz
Faheem wrote: Hi all, How do I replace the same value multiple times without repeating the same variable name/value repeatedly? for ex. some = 'thing' print '%s %s %s %s' % (some,some,some,some) in this case, my question is how do i replace "% (some,some,some)" with something more concis

Re: [Tutor] String Replacement question

2008-05-21 Thread bob gailer
Faheem wrote: Hi all, How do I replace the same value multiple times without repeating the same variable name/value repeatedly? for ex. some = 'thing' print '%s %s %s %s' % (some,some,some,some) in this case, my question is how do i replace "% (some,some,some)" with something more concis

Re: [Tutor] String Replacement Question

2008-05-21 Thread Carlos Hanson
On Wed, May 21, 2008 at 9:39 AM, Jeff Younker <[EMAIL PROTECTED]> wrote: > On May 21, 2008, at 6:42 AM, Kinuthia Muchane wrote: > > st = "String" > print "%s " %st*3 >> >> String String String > >> >> Does this help? > > Another approach is to use dictionaries for string > replacement.

Re: [Tutor] String Replacement Question

2008-05-21 Thread Jeff Younker
On May 21, 2008, at 6:42 AM, Kinuthia Muchane wrote: st = "String" print "%s " %st*3 String String String Does this help? Another approach is to use dictionaries for string replacement. >>> subst = {'some': 'thing'} >>> print "%(some)s%(some)s%(some)s" % subst thingthingthing -jeff ___

Re: [Tutor] String Replacement Question

2008-05-21 Thread Kinuthia Muchane
Moishy Gluck wrote: >>> "%s " %st*3 'String String String ' ^ If you look closely at the end of the string there is an extra space. >>> " ".join((st, )*3) 'String String String' ^ No extra space. Ah...Okay! On Wed, May 21, 2008 at

Re: [Tutor] String Replacement Question

2008-05-21 Thread Moishy Gluck
uot; %st*3 >>>>> >>>> String String String >> >>> >>>>> >> Does this help? >> >> Kinuthia... >> >> - >> >> Message: 6 >> Date: Wed, 21 May 2008 15:05:21 +0530 >

[Tutor] String Replacement Question

2008-05-21 Thread Kinuthia Muchane
st = "String" print "%s " %st*3 String String String Does this help? Kinuthia... - Message: 6 Date: Wed, 21 May 2008 15:05:21 +0530 From: Faheem <[EMAIL PROTECTED]> Subject: [Tutor] String Replacement question To: tutor@python.org Mes

Re: [Tutor] String Replacement question

2008-05-21 Thread Moishy Gluck
Some other solutions might be >>> animal = 'cat' >>> " ".join((animal, ) * 4) 'cat cat cat cat' >>> animal = 'cat' >>> print " ".join((animal, ) * 4) cat cat cat cat >>>#If you need the string injected into another string >>> print "My %s's name is ginger." % (" ".join((animal,) * 4)) My cat cat c

Re: [Tutor] String Replacement question

2008-05-21 Thread Kent Johnson
On Wed, May 21, 2008 at 5:35 AM, Faheem <[EMAIL PROTECTED]> wrote: > Hi all, > How do I replace the same value multiple times without repeating the > same variable name/value repeatedly? > for ex. > > some = 'thing' > print '%s %s %s %s' % (some,some,some,some) You can use named parameters, whi

Re: [Tutor] String Replacement question

2008-05-21 Thread Wolfram Kraus
Am 21.05.2008 11:35, Faheem schrieb: Hi all, How do I replace the same value multiple times without repeating the same variable name/value repeatedly? for ex. some = 'thing' print '%s %s %s %s' % (some,some,some,some) in this case, my question is how do i replace "% (some,some,some)" wit

[Tutor] String Replacement question

2008-05-21 Thread Faheem
Hi all, How do I replace the same value multiple times without repeating the same variable name/value repeatedly? for ex. some = 'thing' print '%s %s %s %s' % (some,some,some,some) in this case, my question is how do i replace "% (some,some,some)" with something more concise? thanks in adv