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:
  #1  
Old August 5th, 2004, 04:19 AM
zeusyuan zeusyuan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 zeusyuan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help,very easy question i think

I have a list like this list =[aaa.123,bbb,456]
I want to split with "." and assin each part of list to a new list like mylist0 = [aaa,123] and mylist1 =[bbb,456]
so I do

list =[aaa.123,bbb,456]
i = 0
while i < len(list):
s = list[i]
mylist+str(i)=s.split(".")
i=i+1
print mylist0

But i got error "can't assign to operator".
Could anyone help me slove this problem?

Reply With Quote
  #2  
Old August 5th, 2004, 07:55 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
You cant create dynamic variables like that saddly. And in most cases i wouldn't even try since a list would be much easier to use etc. You should also note that in order to split a value it has to be a string; not a literal.

Code:
#!/usr/bin/env python

array = ['aaa.123', 'bbb.456']

for (index, value) in enumerate(array):
	array[index] = value.split('.')
	print value


If you really want to declair dynamic variables then you should look at the exec keyword. Look for it in this page:

http://www.python.org/doc/current/lib/built-in-funcs.html

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old August 6th, 2004, 12:46 AM
zeusyuan zeusyuan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 2 zeusyuan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by netytan
You cant create dynamic variables like that saddly. And in most cases i wouldn't even try since a list would be much easier to use etc. You should also note that in order to split a value it has to be a string; not a literal.

Code:
#!/usr/bin/env python

array = ['aaa.123', 'bbb.456']

for (index, value) in enumerate(array):
	array[index] = value.split('.')
	print value


If you really want to declair dynamic variables then you should look at the exec keyword. Look for it in this page:

http://www.python.org/doc/current/lib/built-in-funcs.html

Mark.


Thank you very much.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > help,very easy question i think


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 5 hosted by Hostway
Stay green...Green IT