LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2003, 03:04 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
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
 
Old 10-26-2003, 04:10 PM   #2
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split function (bash script) NiM Programming 11 03-10-2012 07:53 AM
error when run java program vanhelsing Programming 8 12-24-2004 03:23 AM
PERL Q, split function and reg expressions amytys Programming 1 12-08-2004 11:54 AM
Error when program is run JSmith Programming 1 09-17-2004 09:52 PM
program to split and merge files fuelinux Linux - Software 3 10-25-2003 12:56 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration