|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I'm trying to write some Python code... I'm a newbie, and I just can't figure out what I am doing wrong. I get a "can't assign to function call" error on line 10. Here is the code:
import string import sys listhorz = [] listvert = [] for line in open('IPs.csv').readlines(): temp = string.strip(line) listhorz(4)= string.split( 'temp' , ',' ) <== line 10 listvert.append(listhorz) I split up my code, to make sure is was the list assignment. Any ideas? Carrie |
|
#2
|
||||
|
||||
|
What exactly are you trying to do on the
Code:
listhorz(4)= string.split( 'temp' , ',' ) line? It's the (4) that is confusing me and Python. The Code:
listhorz(4) part makes Python (and anyone reading your code) think that you are calling a function called listhorz with one parameter: 4. With Code:
string.split( 'temp' , ',') you're trying to split the string literal 'temp' on the comma character, not the string contained in the variable temp. Here's what I think you are trying to do: Code:
import string
import sys
listhorz = []
listvert = []
for line in open('IPs.csv').readlines():
temp = string.strip(line)
listhorz= string.split( temp, ',' )
listvert.append(listhorz)
Am I right?
__________________
Lucas Marshall |
|
#3
|
|||
|
|||
|
Yes, that was what I was trying to do. I was trying to create a 2D array, and having a little trouble with the construction, due to my examples being all 1D. I eventually wrote this:
for line in open('IPs.csv').readlines(): temp = string.strip(line) data.append(string.split( temp , ',' )) This seems to work very well, and I cleared out all my other issues, but one. I am trying to loop through a list. Essentially, I have a file, and for every line in the file, I need to compare it to the first 2 entries of every line in my 2D array. I'm comparing IP ranges, if that helps. Like this: IP IP Region IP IP Region IP IP Region I know I need to use a statement like one of these: While listentry is not null or for entry in list But, I'm not able to find a good example. Do you have one? Thanks, Carrie |
|
#4
|
|||
|
|||
|
Nevermind, I figured that part out, and went on to another piece of my script.
Now I'm down to just one syntax error, I think. Carrie |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Newbie question about list.append |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|