Python and Regular Expressions

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Apr 7 05:13:33 EDT 2010


Richard Lamboj a écrit :
> Hello,
> 
> i want to parse this String:
> 
> version 3.5.1 {
> 
> 	$pid_dir = /opt/samba-3.5.1/var/locks/
> 	$bin_dir = /opt/samba-3.5.1/bin/
> 
> 	service smbd {
> 		bin = ${bin_dir}smbd -D
> 		pid = ${pid_dir}smbd.pid
> 	}
> 	service nmbd {
> 		bin = ${bin_dir}nmbd -D
> 		pid = ${pid_dir}nmbd.pid
> 	}
> 	service winbindd {
> 		bin = ${bin_dir}winbindd -D
> 		pid = ${pid_dir}winbindd.pid
> 	}
> }

(snip)

I think you'd be better writing a specific parser here. Paul McGuire's 
PyParsing package might help:

http://pyparsing.wikispaces.com/

My 2 cents.



More information about the Python-list mailing list