Re: Very stupid question about a % symbol

2010-09-17 Thread Xavier Ho
On 17 September 2010 12:48, Terry Reedy wrote: > Doubling an escape char, whatever it is, is a common convention: > >>> print("Print a {{}} format string line this: {{{}}}".format(2)) > Print a {} format string line this: {2} > Wow. That's convoluted. Took me a minute to process. Cheers, Xav --

Re: Very stupid question about a % symbol

2010-09-17 Thread Steven D'Aprano
On Thu, 16 Sep 2010 11:25:06 -0400, J wrote: > OK, this is a very stupid question about a very simple topic, but Google > is failing me this morning... [...] Others have already answered your question, but for future reference, many people won't bother to read posts with a meaningless subject li

Re: Very stupid question about a % symbol

2010-09-16 Thread Terry Reedy
On 9/16/2010 12:23 PM, J wrote: Thanks for the replies... I KNEW there was a simple way to escape the % but I had no idea what it was (I just had conviction). I was thrown when the \ didn't escape it... never knew about %%. But now I do! Thanks for the replies! Doubling an escape char, what

Re: Very stupid question about a % symbol

2010-09-16 Thread Jason Swails
Ha, I had this same problem, but I was trying to do dynamic formatting: ("%%%s" % format) % number where "format" is a python-ized fortran format string (i.e. "9.4E"). Looks kinda weird and less elegant than the {0:{1}}-type .format() syntax, but at least it preserves backwards compatibility to

Re: Very stupid question about a % symbol

2010-09-16 Thread J
On Thu, Sep 16, 2010 at 12:09, Grant Edwards wrote: > On 2010-09-16, J wrote: > >> Reported memory amounts are within 10% tolerance > "Reported memory amounts are within %d%% tolerance" % 10 > 'Reported memory amounts are within 10% tolerance' Thanks for the replies... I KNEW there was a si

Re: Very stupid question about a % symbol

2010-09-16 Thread Tim Chase
On 09/16/10 10:25, J wrote: OK, this is a very stupid question about a very simple topic, but print "Reported memory amounts are within %s%s tolerance" % (self.mem_tolerance,'%') Is there a better way to print a '%' in the string when also using formating? I've tried things like this: print "b

Re: Very stupid question about a % symbol

2010-09-16 Thread Grant Edwards
On 2010-09-16, J wrote: > Reported memory amounts are within 10% tolerance >>> "Reported memory amounts are within %d%% tolerance" % 10 'Reported memory amounts are within 10% tolerance' -- Grant Edwards grant.b.edwardsYow! It's the RINSE CYCLE!!

Re: Very stupid question about a % symbol

2010-09-16 Thread Xavier Ho
On 17 September 2010 01:25, J wrote: > Is there a better way to print a '%' in the string when also using > formating? > I believe %% will escape the % and prints it straight out. Cheers, Xav -- http://mail.python.org/mailman/listinfo/python-list

Re: Very stupid question.

2006-03-31 Thread Juha-Matti Tapio
Peter Hansen <[EMAIL PROTECTED]> wrote: > >>> from path import path > >>> path('foobar').getsize() > 12345L > (But note that it's just a nice wrapper around the scattered builtin > ways of doing the same thing, in this case the os.stat().st_size > approach mentioned above. That's not a bad thi

Re: Very stupid question.

2006-03-30 Thread Peter Hansen
On 3/30/06, *Sullivan Zheng* <[EMAIL PROTECTED] > wrote: > > Wow, seems I am not that supid. Why python does not include this > function in the file object. It is almost a tradition in other > languages... > > import os > > os.stat(path).st

Re: Very stupid question.

2006-03-30 Thread Benji York
On 3/30/06, *Sullivan Zheng* <[EMAIL PROTECTED]> wrote: > Wow, seems I am not that supid. Why python does not include this > function in the file object. It is almost a tradition in other > languages... > really not elegant or OO. A file isn't an object. You can get a "file

Re: Very stupid question.

2006-03-30 Thread Sebastjan Trepca
On 3/30/06, Sullivan Zheng <[EMAIL PROTECTED]> wrote: Wow, seems I am not that supid. Why python does not include this function in the file object. It is almost a tradition in other languages...   import os   os.stat(path).st_size   really not elegant or OO.True.-- Sebastjanhttp://www.trepca.si/blo

Re: Very stupid question.

2006-03-30 Thread Jorge Godoy
"Sullivan WxPyQtKinter" <[EMAIL PROTECTED]> writes: > How to get the length of a file via build-in file object support? In > Visual Basic there is len(file) of something like that. But in python, > where is this property? > > Sorry for this stupid question, if it is. pydoc osand then look for

Re: Very stupid question.

2006-03-30 Thread Sebastjan Trepca
Check os.stat() function here http://docs.python.org/lib/os-file-dir.html-- Sebastjanhttp://www.trepca.si/blog On 30 Mar 2006 09:34:32 -0800, Sullivan WxPyQtKinter <[EMAIL PROTECTED]> wrote: In addition, f=file('filename','r');len(f.read()) is quite expensive inmy point of view, If the file is serv

Re: Very stupid question.

2006-03-30 Thread Fredrik Lundh
"Sullivan WxPyQtKinter" wrote: > How to get the length of a file via build-in file object support? In > Visual Basic there is len(file) of something like that. But in python, > where is this property? import os size = os.path.getsize(filename) -- http://mail.python.org/mailman/listinfo/pyt

Re: Very stupid question.

2006-03-30 Thread Sullivan WxPyQtKinter
In addition, f=file('filename','r');len(f.read()) is quite expensive in my point of view, If the file is serveral MB or larger. -- http://mail.python.org/mailman/listinfo/python-list