First of all - thanks for all the replies. (Sorry for my slowness in
answering, but I wrote this message from work, just before leaving for
the weekend.)
I found a couple of posts that might be of interest:
Regarding speed I found a similar discussion in this newsgroup with
interesting results:
ht
Matthew Warren wrote:
> > -Original Message-
> > From:
> > [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]
> > rg] On Behalf Of Gal Diskin
> > Sent: 05 October 2006 16:01
> > To: python-list@python.org
> > Subject: building strings from
On 2006-10-06, MonkeeSage <[EMAIL PROTECTED]> wrote:
> wesley chun wrote:
>> from the performance standpoint, i believe that #4 (list join)
>> from scott is the fastest. #1 (string formatting) is next
>> preferred only because #3 (string concat) is the worst [think
>> "realloc()"]. #2 is useful fo
Ps. For readability you can also roll your own sprintf function:
def format(s, *args, **kwargs):
if args:
return s % args
elif kwargs:
return s % kwargs
else:
return s
s = 'I like %s and %s.'
print format(s, 'ham', 'cheese')
s = 'I like %(b)s and %(c)s.'
print format(s, b='butt
wesley chun wrote:
> from the performance standpoint, i believe that #4 (list join) from
> scott is the fastest. #1 (string formatting) is next preferred only
> because #3 (string concat) is the worst [think "realloc()"]. #2 is
> useful for when you have users who aren't as comfortable with #1.
I
> Following a discussion with an associate at work about various ways to
build strings from variables in python, I'd like to hear your opinions
and preferred methods.
from the performance standpoint, i believe that #4 (list join) from
scott is the fastest. #1 (string formatting) is next preferred
Gal Diskin wrote:
> Following a discussion with an associate at work about various ways to
> build strings from variables in python, I'd like to hear your opinions
> and preferred methods. The methods we discussed are:
> 1. some_string = "cd %s ; %s %d %s %s" % ( working_dir, ssh_cmd,
> some_coun
Gal Diskin wrote:
> Following a discussion with an associate at work about various ways to
> build strings from variables in python, I'd like to hear your opinions
> and preferred methods. The methods we discussed are:
> 1. some_string = "cd %s ; %s %d %s %s" % ( working_dir, ssh_cmd,
> some_cou
> -Original Message-
> From:
> [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> rg] On Behalf Of Gal Diskin
> Sent: 05 October 2006 16:01
> To: python-list@python.org
> Subject: building strings from variables
>
> Following a discussion with an associate
Following a discussion with an associate at work about various ways to
build strings from variables in python, I'd like to hear your opinions
and preferred methods. The methods we discussed are:
1. some_string = "cd %s ; %s %d %s %s" % ( working_dir, ssh_cmd,
some_count, some_param1, some_param2)
10 matches
Mail list logo