Regular Expression

Michael McGarry replytogroup at nospam.org
Wed Dec 15 07:55:26 CET 2004


Binu K S wrote:
> You can do this without regular expressions if you like
> 
> 
>>>>uptime='12:12:05  up 21 days, 16:31, 10 users,  load average:
> 
> 0.01, 0.02, 0.04'
> 
>>>>load = uptime[uptime.find('load average:'):]
>>>>load
> 
> 'load average: 0.01, 0.02, 0.04'
> 
>>>>load = load.split(':')
>>>>load
> 
> ['load average', ' 0.01, 0.02, 0.04']
> 
>>>>load[1].split(',')
> 
> [' 0.01', ' 0.02', ' 0.04']
> 
> One liner:
> 
>>>>uptime[uptime.find('load average:'):].split(':')[1].split(',')[0]
> 
> ' 0.01'
> 

Thank you.



More information about the Python-list mailing list