split and splitfields function cause an error when the program run
split and splitfields function cause an error when the program run
=============================
root:~# ./read-ifconfig_1.py
eth0 = addr:216.143.22.145
eth1 = addr:10.4.0.1
Traceback (most recent call last):
File "./read-ifconfig_1.py", line 16, in ?
eth0_split = splitfields(eth0,":",0)
NameError: name 'splitfields' is not defined
==============================
#!/usr/bin/python
import os, sys, os.path, operator, string
f = os.popen3("ifconfig")
if_config_list = string.strip ( f[1].read() ).split(" ")
eth0 = if_config_list[23]
eth1 = if_config_list[140]
print "\neth0 = ", eth0
print "\neth1 = ", eth1
#eth0 now has a format of addr:216.143.22.145
#I want to get rid of the word "addr:" from the value eth0
eth0_split = splitfileds(eth0,":",0)
print "\neth0_split = ", eth0_split
|