Time in python

tritran tritran2001 at iprimus.com.au
Thu May 30 23:58:18 EDT 2002


I mean we have a directory and that directory contain some of the file, I
want to sort the file according to the time and may be i like to seperate
the file and the time into 2 parts in order to display in the table like
-------------------------------------------------
|File Name                     |    Date                       |
-------------------------------------------------
|file1.txt                         |  28/05/2002 6:30      |
------------------------------------------------
"Peter Hansen" <peter at engcorp.com> wrote in message
news:3CF6DB3C.731E1DD at engcorp.com...
> David Lees wrote:
> >
> > Gold Fish wrote:
> > >
> > > Can anyone tell me how we seperate the time in the file name in
python.
> > > For example
> > > python.txt 28/05/02 06:25
>
> > If you are asking about text processing for a particular type of output,
> > how about:
> >
> > >>> x ='python.txt 28/05/02 06:25'
> > >>> string.split(x)[2]
> > '06:25'
>
> And hope that there are no spaces in the file name.... ;-)
>
> >>> x = 'name with space.txt 28/05/02 06:25'
> >>> x.split(' ')[2]             # brittle
> 'space.txt'
> >>> x.split(' ')[-1]            # better
> '06:25'
> >>> x[x.rfind(' ') + 1 : ]      # kind of ugly
> '06:25'
>
> -Peter





More information about the Python-list mailing list