SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
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  
Old September 18th, 2002, 05:38 PM
Droideka Droideka is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 0 Droideka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Newbie question about list.append

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

Reply With Quote
  #2  
Old September 18th, 2002, 06:31 PM
ZeUs's Avatar
ZeUs ZeUs is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: St. George, Utah
Posts: 63 ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level)ZeUs User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 31
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

Reply With Quote
  #3  
Old September 19th, 2002, 12:18 PM
Droideka Droideka is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 0 Droideka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old September 19th, 2002, 04:04 PM
Droideka Droideka is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 0 Droideka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Newbie question about list.append


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 3 hosted by Hostway