Re: String Formatting with new .format()

2018-03-28 Thread Chris Angelico
On Thu, Mar 29, 2018 at 1:54 AM, Dan Stromberg wrote: > On Wed, Mar 28, 2018 at 7:30 AM, Ganesh Pal wrote: >>> >>> Or maybe they're not giving the same result. I'm a little confused here. >>> >> >> >> My Bad and Apologies , I should be fined for pasting wrong question. >> >> Actually I wanted t

Re: String Formatting with new .format()

2018-03-28 Thread Dan Stromberg
On Wed, Mar 28, 2018 at 7:30 AM, Ganesh Pal wrote: >> >> Or maybe they're not giving the same result. I'm a little confused here. >> > > > My Bad and Apologies , I should be fined for pasting wrong question. > > Actually I wanted to know if its ok to use just empty {} with .format() > or use {

Re: String Formatting with new .format()

2018-03-28 Thread Frank Millman
"Ganesh Pal" wrote in message news:CACT3xuUmOzR=5G9=zaf3fp2lytbgjv74vsyjfsvsifo77lf...@mail.gmail.com... Actually I wanted to know if its ok to use just empty {} with .format() or use {} with values i.e {0} {1} both will give the same results anyway The benefit of using empty {} is that yo

Re: String Formatting with new .format()

2018-03-28 Thread Ganesh Pal
> > Or maybe they're not giving the same result. I'm a little confused here. > My Bad and Apologies , I should be fined for pasting wrong question. Actually I wanted to know if its ok to use just empty {} with .format() or use {} with values i.e {0} {1} both will give the same results anyway

Re: String Formatting with new .format()

2018-03-27 Thread Michael Torrie
On 03/26/2018 09:37 AM, Ganesh Pal wrote: > Hi Team, > > Just a quick suggestion, on string formatting with .format() which of the > below is better , given both give the same result . No they don't. Look more closely at the output. attempts = 1 msg2 = "Hello" print "Retry attempt

Re: String Formatting with new .format()

2018-03-27 Thread Ganesh Pal
> > > Or maybe they're not giving the same result. I'm a little confused here. > > Thanks Chris, for the reply they appear to give the same result . -- https://mail.python.org/mailman/listinfo/python-list

Re: String Formatting with new .format()

2018-03-26 Thread W Yg
在 2018年3月26日星期一 UTC+8下午11:37:46,Ganesh Pal写道: > Hi Team, > > Just a quick suggestion, on string formatting with .format() which of the > below is better , given both give the same result . > > >>> attempts = 1 > >>> msg2 = "Hello" > >>> print "Retry attempt:{0} for error:{1}".format(attempts,msg2

Re: String Formatting with new .format()

2018-03-26 Thread Chris Angelico
On Tue, Mar 27, 2018 at 2:37 AM, Ganesh Pal wrote: > Hi Team, > > Just a quick suggestion, on string formatting with .format() which of the > below is better , given both give the same result . > attempts = 1 msg2 = "Hello" print "Retry attempt:{0} for error:{1}".format(attempts,msg

Re: String formatting

2018-03-25 Thread D'Arcy Cain
Was "Accessing parent objects." On 03/25/2018 12:26 PM, Jugurtha Hadjar wrote: >> print("I am {0.__class__.__name__} foo".format(self)) > > I prefer keyword arguments, but if I used it that way I'd do: > > print("I am {0} foo".format(self.__class__.__name__)) These are contrived examples. In r

Re: % string formatting - what special method is used for %d?

2016-12-11 Thread Veek M
Ian Kelly wrote: > On Sat, Dec 10, 2016 at 11:40 PM, Veek M wrote: >> Well take a look at this: >> ### >> #!/usr/bin/python >> >> class Foo(int): >> def __init__(self, value): >> self.value = value >> >> def __str__(self): >> print '

Re: % string formatting - what special method is used for %d?

2016-12-10 Thread Ian Kelly
On Sat, Dec 10, 2016 at 11:40 PM, Veek M wrote: > Well take a look at this: > ### > #!/usr/bin/python > > class Foo(int): > def __init__(self, value): > self.value = value > > def __str__(self): > print '__str__' > return str(

Re: % string formatting - what special method is used for %d?

2016-12-10 Thread Veek M
Steve D'Aprano wrote: > On Sat, 10 Dec 2016 06:06 pm, Veek M wrote: > >> When we do: >> >> print '%s %d' % ('hello', 10) >> >> what special method is being invoked internally within the string- >> format-specifier? > > %d requires the argument to be an int, or able to be converted to int > usi

Re: % string formatting - what special method is used for %d?

2016-12-10 Thread Steve D'Aprano
On Sat, 10 Dec 2016 06:06 pm, Veek M wrote: > When we do: > > print '%s %d' % ('hello', 10) > > what special method is being invoked internally within the string- > format-specifier? %d requires the argument to be an int, or able to be converted to int using the __int__ special method. py> cl

Re: String formatting - mysql insert

2011-07-14 Thread Christian
On 14 Jul., 17:31, Billy Mays wrote: > On 07/14/2011 11:00 AM, Christian wrote: > > > > > > > > > > > Hi, > > > I get some problem  when i like to set the table name dynamic. > > I'm appreciate for any help. > > > Christian > > > ### works > > newcur.execute (  """ INSERT INTO events (id1,id2

Re: String formatting - mysql insert

2011-07-14 Thread Billy Mays
On 07/14/2011 11:00 AM, Christian wrote: Hi, I get some problem when i like to set the table name dynamic. I'm appreciate for any help. Christian ### works newcur.execute ( """ INSERT INTO events (id1,id2) VALUES (%s,%s); """ , (rs[1],rs[2])) ### works not newcur.execute ( """ INSE

Re: String formatting - mysql insert

2011-07-14 Thread Chris Angelico
On Fri, Jul 15, 2011 at 1:00 AM, Christian wrote: > Hi, > > I get some problem  when i like to set the table name dynamic. > I'm appreciate for any help. > > ### works but is not really perfect: None from rs list result in > "None" instead of NULL. > newcur.execute (  """ INSERT INTO %s_events (id

Re: string formatting

2011-05-10 Thread Raymond Hettinger
> Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old style. (2) and (3) are new but (3) is only > supported from Python 2.7+. > > Which one sho

Re: string formatting

2011-05-10 Thread Chris Angelico
On Wed, May 11, 2011 at 12:15 AM, Web Dreamer wrote: > I was unsure of the difference between deprecated and obsolete. > > So now, if I understand well, obsolete comes before deprecated, such that if > a feature is obsolete it will be deprecated in an unknown future, after > which it will be remov

Re: string formatting

2011-05-08 Thread alex23
harrismh777 wrote: > [...] because *any* time or *most* types > can be substituted and the 'polymorphism' of Python kicks in allowing > for that [...] The same benefit one might get from using the idiomatic 'if not list:'? ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: string formatting

2011-05-07 Thread Terry Reedy
On 5/6/2011 8:09 PM, Chris Angelico wrote: On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: def emsg(x): if isinstance(x,tuple): x = (x,) print(The following object caused a proplem: %s" % x) Couldn't you just do that unconditionally? print(The following object caused a proplem: %s

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 14:39:15 -0500, harrismh777 wrote: > On the other hand, consider this 3.x code snip: > > print("the %s is %d" % ('sky', 'blue')) > > > That formatting will throw an exception, because the format > construct is restricting the format entry to be a number, which 'b

Re: string formatting

2011-05-06 Thread Chris Angelico
On Sat, May 7, 2011 at 6:54 AM, Terry Reedy wrote: > def emsg(x): >  if isinstance(x,tuple): >    x = (x,) >  print(The following object caused a proplem: %s" % x) > Couldn't you just do that unconditionally? print(The following object caused a proplem: %s" % (x,)) Chris Angelico -- http://mail

Re: string formatting

2011-05-06 Thread Terry Reedy
On 5/6/2011 3:22 PM, harrismh777 wrote: I don't really like the old style, not because there is anything wrong with it, There is in that it special cases tuples. For instance, a message function like def emsg(x): print("The following object caused a proplem: %s" % x) raises "TypeError: n

Re: string formatting

2011-05-06 Thread Ian Kelly
On Fri, May 6, 2011 at 1:39 PM, harrismh777 wrote: > harrismh777 wrote:    OP wrote: > >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {}".format('sky', 'blue') > >   On the other hand, consider this 3.x code snip: > >   print("the %s i

Re: string formatting

2011-05-06 Thread Neil Cerutti
On 2011-05-06, harrismh777 wrote: > Steven D'Aprano wrote: >> It's perfectly safe to continue using % formatting, if you >> choose. > > I would hope so, since its the way in most of the books, much > of the doc and a majority of the code... > > I don't really like the old style, not because there

Re: string formatting

2011-05-06 Thread harrismh777
harrismh777 wrote:OP wrote: (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') On the other hand, consider this 3.x code snip: print("the %s is %d" % ('sky', 'blue')) That formatting will throw an exception

Re: string formatting

2011-05-06 Thread harrismh777
Steven D'Aprano wrote: It's perfectly safe to continue using % formatting, if you choose. I would hope so, since its the way in most of the books, much of the doc and a majority of the code... I don't really like the old style, not because there is anything wrong with it, because its

Re: string formatting

2011-05-06 Thread MRAB
On 06/05/2011 16:06, Adam Tauno Williams wrote: On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: On 06/05/2011 08:18, Jabba Laci wrote: Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky',

Re: string formatting

2011-05-06 Thread Adam Tauno Williams
On Fri, 2011-05-06 at 15:58 +0100, MRAB wrote: > On 06/05/2011 08:18, Jabba Laci wrote: > > Which is the preferred way of string formatting? > > (1) "the %s is %s" % ('sky', 'blue') > > (2) "the {0} is {1}".format('sky', 'blue') > > (3) "the {} is {}".format('sky', 'blue') > > As I know (1) is old

Re: string formatting

2011-05-06 Thread MRAB
On 06/05/2011 08:18, Jabba Laci wrote: Hi, Which is the preferred way of string formatting? (1) "the %s is %s" % ('sky', 'blue') (2) "the {0} is {1}".format('sky', 'blue') (3) "the {} is {}".format('sky', 'blue') As I know (1) is old style. (2) and (3) are new but (3) is only supported from

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 14:10:17 +0200, Web Dreamer wrote: > What I would like to know is the difference between "deprecated" and > "obsolete"... Writing x*x instead of x**2 is obsolete, but it will never go away. Writing apply(func, args) instead of func(*args) is deprecated. It has gone away. O

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 02:23:19 -0700, Chris Rebert wrote: > On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano > wrote: >> On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >>> Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans >>> : Hi, Which is the preferred way of string form

Re: string formatting

2011-05-06 Thread nn
On May 6, 8:10 am, Web Dreamer wrote: > Chris Rebert a écrit ce vendredi 6 mai 2011 11:23 dans > : > > > > > I'm not them, but: > > "Note: The formatting operations described here [involving %] are > > obsolete and may go away in future versions of Python. Use the new > > String Formatting [i.e.

Re: string formatting

2011-05-06 Thread Chris Rebert
On Fri, May 6, 2011 at 1:46 AM, Steven D'Aprano wrote: > On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: >> Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans >> : >>> Hi, >>> >>> Which is the preferred way of string formatting? >>> >>> (1) "the %s is %s" % ('sky', 'blue') >>> >>> (2) "t

Re: string formatting

2011-05-06 Thread Steven D'Aprano
On Fri, 06 May 2011 10:00:30 +0200, Web Dreamer wrote: > Jabba Laci a écrit ce vendredi 6 mai 2011 09:18 dans > : > >> Hi, >> >> Which is the preferred way of string formatting? >> >> (1) "the %s is %s" % ('sky', 'blue') >> >> (2) "the {0} is {1}".format('sky', 'blue') >> >> (3) "the {} is {

Re: String formatting with the format string syntax

2010-09-15 Thread Andre Alexander Bell
On 09/15/2010 10:48 AM, Peter Otten wrote: I personally would not be too concerned about the leading underscore, but you can use string.Formatter().parse(template) instead. Thanks for this pointer. I like it this way. So if I now combine your generator with your suggestion, I end up with som

Re: String formatting with the format string syntax

2010-09-15 Thread Peter Otten
Andre Alexander Bell wrote: > On 09/15/2010 10:00 AM, Peter Otten wrote: >> def extract_names(t, recurse=1): >> for _, name, fmt, _ in t._formatter_parser(): >> if name is not None: >> yield name >> if recurse and fmt is not None: >> for name in ext

Re: String formatting with the format string syntax

2010-09-15 Thread Andre Alexander Bell
On 09/15/2010 10:00 AM, Peter Otten wrote: def extract_names(t, recurse=1): for _, name, fmt, _ in t._formatter_parser(): if name is not None: yield name if recurse and fmt is not None: for name in extract_names(fmt, recurse-1): yi

Re: String formatting with the format string syntax

2010-09-15 Thread Peter Otten
Peter Otten wrote: > Andre Alexander Bell wrote: > >> On 09/14/2010 08:20 PM, Miki wrote: >>> You can use ** syntax: >> english = {'hello':'hello'} >> s.format(**english) >> >> Thanks for your answer. Actually your answer tells me that my example >> was misleading. Consider the template

Re: String formatting with the format string syntax

2010-09-14 Thread Peter Otten
Andre Alexander Bell wrote: > On 09/14/2010 08:20 PM, Miki wrote: >> You can use ** syntax: > english = {'hello':'hello'} > s.format(**english) > > Thanks for your answer. Actually your answer tells me that my example > was misleading. Consider the template > > s = 'A template with {vari

Re: String formatting with the format string syntax

2010-09-14 Thread Andre Alexander Bell
On 09/14/2010 08:20 PM, Miki wrote: You can use ** syntax: english = {'hello':'hello'} s.format(**english) Thanks for your answer. Actually your answer tells me that my example was misleading. Consider the template s = 'A template with {variable1} and {variable2} placeholders.' I'm seeking

Re: String formatting with the format string syntax

2010-09-14 Thread Benjamin Kaplan
On Tue, Sep 14, 2010 at 3:20 PM, Thomas Jollans wrote: > On Tuesday 14 September 2010, it occurred to Miki to exclaim: >> You can use ** syntax: >> >>> english = {'hello':'hello'} >> >>> s.format(**english) > > No, you can't. This only works with dicts, not with arbitrary mappings, or > dict subcl

Re: String formatting with the format string syntax

2010-09-14 Thread Thomas Jollans
On Tuesday 14 September 2010, it occurred to Miki to exclaim: > You can use ** syntax: > >>> english = {'hello':'hello'} > >>> s.format(**english) No, you can't. This only works with dicts, not with arbitrary mappings, or dict subclasses that try to do some kind of funny stuff. > > On Sep 14,

Re: String formatting with the format string syntax

2010-09-14 Thread Miki
You can use ** syntax: >>> english = {'hello':'hello'} >>> s.format(**english) On Sep 14, 9:59 am, Andre Alexander Bell wrote: > Hello, > > I'm used to write in Python something like > >  >>> s = 'some text that says: %(hello)s' > > and then have a dictionary like > >  >>> english = { 'hello': 'h

Re: String Formatting Operations for decimals.

2010-04-01 Thread Maxim Lacrima
Hello, Chris! Thanks for your really quick reply! It works! On 1 April 2010 12:14, Chris Rebert wrote: > On Thu, Apr 1, 2010 at 2:08 AM, Lacrima wrote: > > Hello! > > > > I need to format a decimal (floating point) number in the following > > way: > > 10 results in '10' > > 10.5 results in '1

Re: String Formatting Operations for decimals.

2010-04-01 Thread Xavier Ho
Hi Maxim, If it's the trailing zeroes you're concerned about, here's a work-around: >>> ('%.2f' % 10.5678).rstrip('0') '10.57 I'm sure there are better solutions. But this one works for your need, right? Cheers,' Ching-Yun Xavier Ho, Technical Artist Contact Information Mobile: (+61) 04 3335

Re: String Formatting Operations for decimals.

2010-04-01 Thread Chris Rebert
On Thu, Apr 1, 2010 at 2:08 AM, Lacrima wrote: > Hello! > > I need to format a decimal (floating point) number in the following > way: > 10 results in '10' > 10.5 results in '10.5' > 10.50 results in '10.5' > 10.5678 results in 10.57 > > How can I achieve this using standard Python string formatti

Re: string formatting documentation

2009-01-19 Thread Alan G Isaac
On 1/19/2009 5:03 PM Terry Reedy apparently wrote: I have not seen 3.0 emit a % deprecation warning. Point taken. But the vocabulary of PEP 4 suggests that "obsolete" and "deprecated" are synonyms, and PEP 4 lists obsolete modules without deprecation warnings. Alan Isaac -- http://mail.pytho

Re: string formatting documentation

2009-01-19 Thread Alan G Isaac
On 1/19/2009 3:03 PM John Machin apparently wrote: It is not deprecated YET; see this: http://docs.python.org/3.0/whatsnew/3.0.html#changes-already-present-in-python-2-6 PEP 3101: Advanced String Formatting. Note: the 2.6 description mentions the format() method for both 8-bit and Unicode strin

Re: string formatting documentation

2009-01-19 Thread Terry Reedy
Alan G Isaac wrote: On Mon, 19 Jan 2009 14:44:01 +, Alan G Isaac wrote: we are supposed to prefer No, no 'supposed to's. You are not even 'supposed to' like or use Python. (Unless, I supposed, an employer demands it. But that is another story.) Certainly, one is not 'supposed to' pre

Re: string formatting documentation

2009-01-19 Thread Steven D'Aprano
On Mon, 19 Jan 2009 15:38:02 +, Alan G Isaac wrote: > But of more interest: you claim PEP 4 is not relevant, and that old > string formatting is NOT deprecated. I would like assurance that it is > not deprecated. Can you back that? If you want to know what python-dev have in mind, you have to

Re: string formatting documentation

2009-01-19 Thread John Machin
On Jan 20, 2:38 am, Alan G Isaac wrote: > But of more interest: you claim PEP 4 is not relevant, > and that old string formatting is NOT deprecated. > I would like assurance that it is not deprecated. It is not deprecated YET; see this: http://docs.python.org/3.0/whatsnew/3.0.html#changes-alread

Re: string formatting documentation

2009-01-19 Thread Alan G Isaac
On Mon, 19 Jan 2009 14:44:01 +, Alan G Isaac wrote: we are supposed to prefer '{0:>10}'.format('wtf?') to '%10s' % 'wtf?' and '{{0}}{0}'.format('wtf?').format('wtf?') to '%%s%s' % 'wtf?' % 'wtf?' On 1/19/2009 10:01 AM Steven D'Aprano apparently wrote: Well, that second example certainly

Re: string formatting documentation

2009-01-19 Thread Steven D'Aprano
On Mon, 19 Jan 2009 14:44:01 +, Alan G Isaac wrote: > On 1/17/2009 3:59 PM Ned Deily apparently wrote: >> > > > Ah, so the rumors are true: > we are supposed to prefer > '{0:>10}'.format('wtf?') > to > '%10s

Re: string formatting documentation

2009-01-19 Thread Alan G Isaac
On 1/17/2009 3:59 PM Ned Deily apparently wrote: Ah, so the rumors are true: we are supposed to prefer '{0:>10}'.format('wtf?') to '%10s' % 'wtf?' and '{{0}}{0}'.format('wtf?').format('wtf?') to '%%s%s' % 'wtf?

Re: String formatting with %s

2007-12-03 Thread Tim Chase
>> dictionary-key/value syntax), you can do something like: > number = lambda x: dict((str(i+1), v) for (i,v) in enumerate(x)) > "%(2)s and %(1)s" % number(["A", "B"]) > > Whoa - that'll take me a little while to figure out, but it looks intriguing! It basically just returns a dictionary

Re: String formatting with %s

2007-12-02 Thread Donn
> dictionary-key/value syntax), you can do something like: > >>> number = lambda x: dict((str(i+1), v) for (i,v) in enumerate(x)) > >>> "%(2)s and %(1)s" % number(["A", "B"]) Whoa - that'll take me a little while to figure out, but it looks intriguing! Tah. \d -- http://mail.python.org/mailman/l

Re: String formatting with %s

2007-12-02 Thread Tim Chase
> I'm sure I one read somewhere that there is a simple way to set the order > of replacements withing a string *without* using a dictionary. > > What I mean is: s = "%s and %s" % ( "A", "B" ) print s > A and B > > Now, is there something quick like: s = "%s/2 and %s/1" % ( "A", "B

Re: String formatting with %s

2007-12-02 Thread James Matthews
try to import printf using ctypes On Dec 2, 2007 7:49 PM, MRAB <[EMAIL PROTECTED]> wrote: > On Dec 2, 1:35 pm, Donn Ingle <[EMAIL PROTECTED]> wrote: > > Hi, > > I'm sure I one read somewhere that there is a simple way to set the > order > > of replacements withing a string *without* using a dict

Re: String formatting with %s

2007-12-02 Thread MRAB
On Dec 2, 1:35 pm, Donn Ingle <[EMAIL PROTECTED]> wrote: > Hi, > I'm sure I one read somewhere that there is a simple way to set the order > of replacements withing a string *without* using a dictionary. > > What I mean is:>>> s = "%s and %s" % ( "A", "B" ) > >>> print s > > A and B > > Now, is th

Re: String formatting with %s

2007-12-02 Thread Donn Ingle
> but not Python, AFAIK Damn! \d -- http://mail.python.org/mailman/listinfo/python-list

Re: String formatting with %s

2007-12-02 Thread Mel
Donn Ingle wrote: > Now, is there something quick like: s = "%s/2 and %s/1" % ( "A", "B" ) print s > B and A > > ? GNU glibc printf accepts a format string: printf ("%2$s and %1$s", "A", "B"); to produce what you want -- but not Python, AFAIK. Mel. -- http://mail.python.o

Re: String formatting for complex writing systems

2007-07-02 Thread Andy
Thanks guys! I've used the HTML and the unicodedata suggestions, each on a different report. These worked nicely! Andy -- http://mail.python.org/mailman/listinfo/python-list

Re: String formatting for complex writing systems

2007-06-27 Thread Leo Kislov
On Jun 27, 3:10 am, Leo Kislov <[EMAIL PROTECTED]> wrote: > On Jun 27, 12:20 am, Andy <[EMAIL PROTECTED]> wrote: > > > Hi guys, > > > I'm writing a piece of software for some Thai friend.  At the end it > > is supposed to print on paper some report with tables of text and > > numbers.  When I test

Re: String formatting for complex writing systems

2007-06-27 Thread Leo Kislov
On Jun 27, 12:20 am, Andy <[EMAIL PROTECTED]> wrote: > Hi guys, > > I'm writing a piece of software for some Thai friend.  At the end it > is supposed to print on paper some report with tables of text and > numbers.  When I test it in English, the columns are aligned nicely, > but when he tests it

Re: String formatting for complex writing systems

2007-06-27 Thread Gabriel Genellina
En Wed, 27 Jun 2007 04:20:52 -0300, Andy <[EMAIL PROTECTED]> escribió: > I'm writing a piece of software for some Thai friend. At the end it > is supposed to print on paper some report with tables of text and > numbers. When I test it in English, the columns are aligned nicely, > but when he tes

Re: String formatting with fixed width

2007-03-16 Thread Alexander Eisenhuth
Thanks for your fast reply. I'm fine with your "%7.03f" solution. (negatives are not significant) Alexander Eisenhuth schrieb: > Hello alltogether, > > is it possible to format stings with fixed width of let's say 7 > character. T need a floating point with 3 chars before dot, padded with >

Re: String formatting with fixed width

2007-03-16 Thread Steve Holden
Steve Holden wrote: > Alexander Eisenhuth wrote: >> Hello alltogether, >> >> is it possible to format stings with fixed width of let's say 7 character. T >> need a floating point with 3 chars before dot, padded with ' ' and 3 chars >> after >> dot, padded with '0'. >> >> Followingh is my approac

Re: String formatting with fixed width

2007-03-16 Thread Jon Clements
On 16 Mar, 13:20, Alexander Eisenhuth <[EMAIL PROTECTED]> wrote: > Hello alltogether, > > is it possible to format stings with fixed width of let's say 7 character. T > need a floating point with 3 chars before dot, padded with ' ' and 3 chars > after > dot, padded with '0'. > > Followingh is my a

Re: String formatting with fixed width

2007-03-16 Thread Steve Holden
Alexander Eisenhuth wrote: > Hello alltogether, > > is it possible to format stings with fixed width of let's say 7 character. T > need a floating point with 3 chars before dot, padded with ' ' and 3 chars > after > dot, padded with '0'. > > Followingh is my approach > >>> f = 21.1 > >>> s =

Re: string formatting: engineering notation

2007-03-14 Thread Darren Dale
[EMAIL PROTECTED] wrote: > On Mar 14, 1:14 pm, Darren Dale <[EMAIL PROTECTED]> wrote: >> Does anyone know if it is possible to represent a number as a string with >> engineering notation (like scientific notation, but with 10 raised to >> multiples of 3: 120e3, 12e-6, etc.). I know this is possibl

Re: string formatting: engineering notation

2007-03-14 Thread attn . steven . kuo
On Mar 14, 1:14 pm, Darren Dale <[EMAIL PROTECTED]> wrote: > Does anyone know if it is possible to represent a number as a string with > engineering notation (like scientific notation, but with 10 raised to > multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the > decimal.Decimal cl

Re: string formatting: engineering notation

2007-03-14 Thread Jorge Godoy
Steve Holden <[EMAIL PROTECTED]> writes: > Darren Dale wrote: >> Does anyone know if it is possible to represent a number as a string with >> engineering notation (like scientific notation, but with 10 raised to >> multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the >> decimal.De

Re: string formatting: engineering notation

2007-03-14 Thread Grant Edwards
On 2007-03-14, Steve Holden <[EMAIL PROTECTED]> wrote: > Darren Dale wrote: >> Does anyone know if it is possible to represent a number as a string with >> engineering notation (like scientific notation, but with 10 raised to >> multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the

Re: string formatting: engineering notation

2007-03-14 Thread Darren Dale
Steve Holden wrote: > Darren Dale wrote: >> Does anyone know if it is possible to represent a number as a string with >> engineering notation (like scientific notation, but with 10 raised to >> multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the >> decimal.Decimal class, but repe

Re: string formatting: engineering notation

2007-03-14 Thread Steve Holden
Darren Dale wrote: > Does anyone know if it is possible to represent a number as a string with > engineering notation (like scientific notation, but with 10 raised to > multiples of 3: 120e3, 12e-6, etc.). I know this is possible with the > decimal.Decimal class, but repeatedly instantiating Decima

Re: String formatting with nested dictionaries

2006-08-24 Thread Maric Michaud
Le jeudi 24 août 2006 21:02, Fredrik Lundh a écrit : > class wrapper: >      def __init__(self, dict): > self.dict = dict >      def __getitem__(self, key): > try: >    return self.dict[key] > except KeyError: >     Quite the same idea, but without eval and the

Re: String formatting with nested dictionaries

2006-08-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I've got a bit of code which has a dictionary nested within another > dictionary. I'm trying to print out specific values from the inner > dict in a formatted string and I'm running into a roadblock. I can't > figure out how to get a value from the inner dict into the

Re: String formatting with nested dictionaries

2006-08-24 Thread [EMAIL PROTECTED]
Gabriel Genellina wrote: > At Thursday 24/8/2006 13:22, [EMAIL PROTECTED] wrote: > > >I've got a bit of code which has a dictionary nested within another > >dictionary. I'm trying to print out specific values from the inner > >dict in a formatted string and I'm running into a roadblock. I can't

Re: String formatting with nested dictionaries

2006-08-24 Thread Gabriel Genellina
At Thursday 24/8/2006 13:22, [EMAIL PROTECTED] wrote: I've got a bit of code which has a dictionary nested within another dictionary. I'm trying to print out specific values from the inner dict in a formatted string and I'm running into a roadblock. I can't figure out how to get a value from t

Re: String formatting with nested dictionaries

2006-08-24 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > I've got a bit of code which has a dictionary nested within another > dictionary. I'm trying to print out specific values from the inner > dict in a formatted string and I'm running into a roadblock. I can't > figure out how to get a value from the inner dict into the

Re: String Formatting

2006-08-10 Thread John Machin
OriginalBrownster wrote: > Hi there: > > I was wondering if its at all possible to search through a string for a > specific character. Don't wonder; read the tutorials, read the manuals, and ponder the sheer uselessness of any computer language that offered neither such a facility nor the means to

Re: String Formatting

2006-08-10 Thread alisonken1
Sorry, missed an option in there: > def get_word(s, which=1, sep=','): > return s.split(sep)[which-1].strip() > > >>> > >>> get_word('bread, butter, milk') > 'milk' > > >>> >>> get_word('bread, butter, milk') 'bread' >>> get_word('bread, butter, milk', 3) 'milk' >>> get_word('bread is brown

Re: String Formatting

2006-08-10 Thread alisonken1
alisonken1 wrote: > OriginalBrownster wrote: > > > Example sorry, forgot the '... everything after the last comma ...' part. -- http://mail.python.org/mailman/listinfo/python-list

Re: String Formatting

2006-08-10 Thread alisonken1
OriginalBrownster wrote: > Example > > If i had a list:bread, butter, milk def get_word(s, which=1, sep=','): return s.split(sep)[which-1].strip() >>> >>> get_word('bread, butter, milk') 'milk' >>> -- http://mail.python.org/mailman/listinfo/python-list

Re: String Formatting

2006-08-10 Thread Simon Forman
OriginalBrownster wrote: > Hi there: > > I was wondering if its at all possible to search through a string for a > specific character. > > I want to search through a string backwords and find the last > period/comma, then take everything after that period/comma > > Example > > If i had a list:b

Re: String Formatting

2006-08-10 Thread Avell Diroll
OriginalBrownster wrote: > Hi there: > > I was wondering if its at all possible to search through a string for a > specific character. > > I want to search through a string backwords and find the last > period/comma, then take everything after that period/comma > > Example > > If i had a list:

Re: String Formatting

2006-08-10 Thread Pontus Ekberg
On Thu, 10 Aug 2006 05:35:26 -0700, OriginalBrownster wrote: > Hi there: > > I was wondering if its at all possible to search through a string for a > specific character. > > I want to search through a string backwords and find the last > period/comma, then take everything after that period/comm

Re: String formatting using dictionaries

2006-04-22 Thread Clodoaldo Pinto
Thank you guys, you are great! -- http://mail.python.org/mailman/listinfo/python-list

Re: String formatting using dictionaries

2006-04-22 Thread Fredrik Lundh
Clodoaldo Pinto wrote: > I know how to format strings using a dictionary: > > >>> d = {'list':[0, 1]} > >>> '%(list)s' % d > '[0, 1]' > > Is it possible to reference an item in the list d['list']?: > > >>> '%(list[0])s' % d > Traceback (most recent call last): > File "", line 1, in ? > KeyError:

Re: String formatting using dictionaries

2006-04-22 Thread Peter Otten
Clodoaldo Pinto wrote: > I know how to format strings using a dictionary: > d = {'list':[0, 1]} '%(list)s' % d > '[0, 1]' > > Is it possible to reference an item in the list d['list']?: > '%(list[0])s' % d > Traceback (most recent call last): > File "", line 1, in ? > KeyError:

Re: string formatting using the % operator

2005-06-13 Thread Peter Hansen
Dan Sommers wrote: > Let the DB-API do more work for you: > > cursor = connection.cursor( ) > sql = """SELECT column2, columns3 FROM table WHERE name LIKE %s""" > values = ('%%%s%%' % searchterm,) # note that this is a tuple It looks like this might be a rare case where not using the

Re: string formatting using the % operator

2005-06-13 Thread William Gill
Dan Sommers wrote: > On Mon, 13 Jun 2005 15:12:54 GMT, > William Gill <[EMAIL PROTECTED]> wrote: > > >>I am using the % operator to create queries for a db app. It works fine >>when exact strings, or numbers are used, but some queries need partial >>matching that use the '%' as a wildcards. So f

Re: string formatting using the % operator

2005-06-13 Thread Dan Sommers
On Mon, 13 Jun 2005 15:12:54 GMT, William Gill <[EMAIL PROTECTED]> wrote: > I am using the % operator to create queries for a db app. It works fine > when exact strings, or numbers are used, but some queries need partial > matching that use the '%' as a wildcards. So for example the resultant > s

Re: string formatting using the % operator

2005-06-13 Thread harold fellermann
> to return 'WHERE name LIKE %smith%'I have tried using escapes, > character codes for the % sign, and lots of other gyrations with no > success. The only thing that works is if I modify searchterm first: > >searchterm = 'smith' >searchterm ='%'+'smith'+'%' >sql += 'WHE

Re: string formatting using the % operator

2005-06-13 Thread fargo
William Gill wrote: > I am using the % operator to create queries for a db app. It works fine > when exact strings, or numbers are used, but some queries need partial > matching that use the '%' as a wildcards. So for example the resultant > string should be 'WHERE name LIKE %smith%' (would ma

Re: string formatting quirk?

2005-05-20 Thread Peter Otten
[EMAIL PROTECTED] wrote: > ''%([]) doesn't raise exception > but > ''%('') does > > Can anyone explain me why?? That is a side-effect of duck-typing. The duck-type of an empty list is indistinguishable from that of an empty dictionary. Not testing the exact type here achieves consistency with th

Re: String formatting strangeness

2005-05-13 Thread dark . ryder
*hides face* Groan! This is what I get for trying to code first thing in the morning. Thanks, all, it works fine now... -- http://mail.python.org/mailman/listinfo/python-list

Re: String formatting strangeness

2005-05-13 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > > Traceback (most recent call last): > File "X:\Music (FLAC)\Post-process new rips.py", line 50, in ? > print "\t\t\t length=\"%i:%i\"/>\n" % [number, name, seconds // 60, seconds % 60] > TypeError: int argument required > > Wait, what? The first line clearly

Re: String formatting strangeness

2005-05-13 Thread Larry Bates
The argument to string format expression needs to be a tuple not a list. Also, all the string escaping makes this very hard to read. You can mix single and double quotes to achieve: print '\t\t\t\n' % \ (number, name, seconds // 60, seconds % 60) which IMHO is much easier to read. Larry

  1   2   >