Re: Thousand Seperator

2008-03-14 Thread Paul M¢Nett
Eddie Corns wrote:
> [EMAIL PROTECTED] writes:
> 
>> I'm trying to find some code that will turn:
> 
>> 100 -> 100
>> 1000 -> 1,000
>> 100 -> 1,000,000
>> -1000 -> -1,000
> 
>> I know that can be done using a regular expression. In Perl I would do
>> something like:
> 
>> sub thousand {
>>$number = reverse $_[0];
>>$number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;
>>return scalar reverse $number;
>> }
> 
>> But I cannot find how to do this in Python.
> 
> Look at the locale module.  If you're producing the numbers yourself then they
> get printed in that format otherwise you can convert them to numbers first.

Specifically:

import locale
locale.setlocale(locale.LC_ALL, '')
for trial in (100, 1000, 100, -1000):
print trial, locale.format("%0f", trial, True)

If that results in no comma separators, then you may need to set the 
locale specifically, such as:

 >>> locale.setlocale(locale.LC_ALL, 'en_us')
'en_us'
 >>> for trial in (100, 1000, 10, -1000):
... print trial, locale.format("%.0f", trial, True)
...
100 100
1000 1,000
10 100,000
-1000 -1,000

Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.path.getsize() on Windows

2008-03-21 Thread Paul M¢Nett
Martin v. Löwis wrote:
>> def isGrowing(f, timeout):
>> ssize = os.path.getsize(f)
>> time.sleep(timeout)
>> esize =os.path.getsize(f)
>> return esize != ssize
>>
>> On windows, this returns the size of the file as it _will be_, not the
>> size that it currently is. 
> 
> Why do you say that? It most definitely returns what the size currently
> is, not what it will be in the future (how could it know, anyway).

I've seen this before, when copying a file in Windows. Windows reports 
the size the file will be after the copy is complete (it knows, after 
all, the size of the source file). I always thought this meant that 
Windows is just much smarter than me, so I ignored it.

Paul
-- 
http://mail.python.org/mailman/listinfo/python-list