[Tutor] need advice on streamlining code...

Chad Crabtree flaxeater at yahoo.com
Mon Jan 17 20:05:59 CET 2005


I can't really think of a more elegant solution than what you have, 
maybe regex's but I hate those.  You *can* reduce the number of lines
by 
two, and there was a variable you never used.
HTH
Eric L. Howard wrote:

>The following block of code works, and provides the necessary output
I'm
>looking for...but I have a feeling that it's working through sheer
brute
>force and could be better:
>
>    insideipgrepfd = os.popen("grep ifconfig_fxp0 /etc/rc.conf")
>    insideipgrep = insideipgrepfd.readlines()
>  
>
insideipgrep=os.popen("grep ifconfig_fxp0 /etc/rc.conf").readlines()

>    insideipfield, insideip =
string.split(string.strip(insideipgrep[0]), "=")
>  
>
insideip = string.split(string.strip(insideipgrep[0]), "=")[1]

>    insideipsplit = string.split(insideip, " ")
>    insideipquads = string.split(insideipsplit[1], ".")
>    insidemaskquads = string.split(insideipsplit[4], ".")
>  
>
insideipquads=string.split(string.split(insideip, " ")[1],".")
insidemaskquads = string.split(string.split(insideip, " ")[4], ".")

>the line in /etc/rc.conf looks like:
>
>ifconfig_fxp0="inet 172.31.2.100 netmask 255.255.255.0"
>
>Any and all thoughts/pointers are appreciated.
>
>    ~elh
>
>  
>



		
__________________________________ 
Do you Yahoo!? 
Meet the all-new My Yahoo! - Try it today! 
http://my.yahoo.com 
 



More information about the Tutor mailing list