[Tutor] need advice on streamlining code...

Kent Johnson kent37 at tds.net
Tue Jan 18 12:00:28 CET 2005


Jacob S. wrote:
> insideipgrep = insideipgrep.lstrip("ifconfig_fxp0=\"inet ")

No! The argument to lstrip() is a list of characters, any of which will be stripped! It is *not* a 
prefix to remove!

  >>> insideipgrep='ifconfig if 00=_xxx Wow'
  >>> insideipgrep.lstrip("ifconfig_fxp0=\"inet ")
'Wow'

You could use
insideipgrep = insideipgrep[len("ifconfig_fxp0=\"inet "):]

One minor suggestion - use embedded underscores or capital letters to make your variable names 
easier to read - instead of insideipgrep use insideIpGrep or inside_ip_grep.

Kent



More information about the Tutor mailing list