Time in python
Peter Hansen
peter at engcorp.com
Thu May 30 22:09:00 EDT 2002
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