> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Ed Leafe > Sent: Sunday, August 12, 2007 8:35 AM > To: Dabo Users list > Subject: Re: [dabo-users] IIF() > > On Aug 12, 2007, at 10:10 AM, Jeff Johnson wrote: > > > This is my approach to the problem presented. I would have used > > arrays in > > FoxPro and lists seem to provide the same functionality (and more). > > > > How would I concatenate the "s" or "ies" at the end of the following > > statement" > > > > print str(givetocustomer[lni]) + ' ' + money[lni] > > Generally you would use string formatting to do this. This is a > Python skill that comes in extremely handy. It is also much more > efficient, since it doesn't create several separate string objects, > and then a new object as each piece is concatenated. Remember, in > Python strings are immutable, so anything that "modifies" a string > actually has to create an entirely new object. > > Your example could be written as: > > print "%s %s" % (givetocustomer[lni]), money[lni]) > > Note that you don't have to explicitly change the 'givetocustomer' > value to a string; that's done by the formatting. You also have an un- > Pythonic loop; it would be better written (without the Hungarian > notation, too!): > > for pos, denom in denominations: > # floor division yields no decimals and no rounding > givetocustomer[pos] = change // denom > # modulus returns remainder > change = change % denom > if givetocustomer[pos] > 0: > if givetocustomer[pos] > 1: > print str(givetocustomer[pos]) + ' ' + > moneys[pos] > else: > print str(givetocustomer[pos]) + ' ' + money[pos] > > -- Ed Leafe > -- http://leafe.com > -- http://dabodev.com > >
That's the kind of advice I was looking for. Thanks Ed! Jeff Jeff Johnson [EMAIL PROTECTED] 623-582-0323 Fax 623-869-0675 --- StripMime Report -- processed MIME parts --- multipart/signed text/plain (text body -- kept) application/x-pkcs7-signature --- _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users Searchable Archives: http://leafe.com/archives/search/dabo-users This message: http://leafe.com/archives/byMID/dabo-users/[EMAIL PROTECTED]
