Sort files by date

2005-07-12 Thread fargo
Hi.

I'm looking for some way to sort files by date.

I'm usin glob module to list a directiry, but files are sorted by name.

 >>> import glob
 >>> path = "./"
 >>> for ScannedFile in glob.glob(path):
... print ScannedFile

I googled my problem, but did not find any solution, neither in this 
newsgroup.

Can anyone help me ?

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


Re: Sort files by date

2005-07-12 Thread fargo
Jeremy Sanders wrote:

> you could do something like:
> 
> l = [(os.stat(i).st_mtime, i) for i in glob.glob('*')]
> l.sort()
> files = [i[1] for i in l]

Thank you for your help, this is excatly what I wasa looking for.
-- 
http://mail.python.org/mailman/listinfo/python-list


MD5 problem

2005-06-13 Thread fargo
Hi.

I'm in trouble with the md5 module.

Under Linux, it's ok, I get real signatures.

The problem is under Windows XP, with some kind of files.

If I use the md5 module with .txt files, it'ok.

The Problem comes from the .msg files. I get the same signature for 
every .msg file I try to hash with the md5 algorithm. I think some 
character are strange for python, and makes it stop before the end of 
the .msg file.

So, my question is : Do anybody have a solution to this problem ? (I can 
post my source code if needed)

Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MD5 problem

2005-06-13 Thread fargo
Roel Schroeven wrote:
> fargo wrote:
> 
>> Hi.
>>
>> I'm in trouble with the md5 module.
>>
>> Under Linux, it's ok, I get real signatures.
>>
>> The problem is under Windows XP, with some kind of files.
>>
>> If I use the md5 module with .txt files, it'ok.
>>
>> The Problem comes from the .msg files. I get the same signature for 
>> every .msg file I try to hash with the md5 algorithm. I think some 
>> character are strange for python, and makes it stop before the end of 
>> the .msg file.
> 
> 
> That sounds like you opened the file in text mode. For things like this 
> it is better to open it in binary mode: file(filename, 'rb')

It was excatly the problem.

Thank you for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


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 match silversmith, 
> smithy, and smith).  Is there any way to get something like
> 
>   searchterm = 'smith'
>   sql += 'WHERE name LIKE %s'  %  searchterm
> 
> 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 += 'WHERE name LIKE %s'  %  searchterm
> 
> Any Ideas?
try this :

sql += 'WHERE name LIKE %%%s%%'  %  searchterm
-- 
http://mail.python.org/mailman/listinfo/python-list