Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 26th, 2003, 01:58 PM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
split and splitfields function cause an error when the program run

split and splitfields function cause an error when the program run

=============================
Traceback (most recent call last):
File "./read-ifconfig_1.py", line 15, in ?
split(eth0,":",0)
NameError: name 'split' 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 = split(eth0,":",0)
print "\neth0_split = ", eth0_split

Reply With Quote
  #2  
Old October 26th, 2003, 03:09 PM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
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 With Quote
  #3  
Old October 26th, 2003, 07:45 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,440 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 50 m 56 sec
Reputation Power: 797
Re: reply

Quote:
Originally posted by linh
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.

That's because split and splitfields are in the string module. Either import everything from the string module like this:
from string import *
foo = split(somestring, separator)

or qualify the namespace:
import string
foo = string.split(somestring, separator)
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
  #4  
Old October 27th, 2003, 09:36 AM
linh linh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 245 linh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 27 sec
Reputation Power: 6
reply

Thank you Scorpions4ever. You are always a big help.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > split and splitfields function cause an error when the program run


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway