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 |
reply
The statement below will solve the problem. As for the original problem, the function
split(s[, sep[, maxsplit]]) and splitfields(s[, sep[, maxsplit]]) are defined in the Python manual I am not sure why it does not work. ====================================== for i in eth0: eth0_split = eth0.split(":",1) print "The colon split at position number. i = ", i print "eth0_split = ", eth0_split |
All times are GMT -5. The time now is 08:29 AM. |