| Reply | « Previous Thread | Next Thread » |
|
Hello everyone,
i have got a file with 3 numbers each row separated with space, i would like to save the 3 numbers in variables for each row How can i do that ? Someone Can help me im kind of novice ? Thanks |
|
Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
|
Quote:
i think you can do that just read the file using the readline function and use that in a loop that can help you a bit. there is a wiki article on this actually i am on mobile so cant find exactly that but this can help you. Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
Quote:
this may help u... |
|
hi djsid,
You can follow this sample code Code:
f=open('/home/seer/abc','r') # Change the file path to the path you want
xyz=f.read()
i=0
while ( ord( xyz[i] )!= 32 ): # Here you check for blank spaces
print xyz[i] # Here instead you assign them to variables
i=i+1
IDEAS is all they need but still they think only Genius can give them that. |
| shubhendra |
| View Public Profile |
| Find all posts by shubhendra |
|
Quote:
Code:
(a, b, c) = line.split(' ')
--jouni |
|
Oh Thanks Jouni, how can i forget "split".
![]() IDEAS is all they need but still they think only Genius can give them that. |
| shubhendra |
| View Public Profile |
| Find all posts by shubhendra |
|
I agree your hmph, Jouni. But anyway "djsid" said: "i would like to save the 3 numbers in variables for each row". Use list comprehension to get integers (feel free to use float()) in one line:
a,b,c = [int(x) for x in line.split(' ')] (Oh, how much I love Python. "Programming is fun (again)!". :-) |
|
Thanks everyone
I used this code to solve my problem Code:
for line in inp.readlines(): numbers = map(int, line.split()) arr.append(numbers) ![]() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Theme Studio 3.1 not creating themes | zemm | Themes/Carbide.ui | 11 | 2008-10-18 09:41 |
| Error : Cannot find file : for DUMMIES | PACALA_BA | General Symbian C++ | 7 | 2008-07-06 14:18 |
| [announce] PyUIQ. Python for UIQ 2.1 and 3.x | OscarBernabeu | Python | 35 | 2008-01-17 10:12 |
| Retrieve data from server-side asp | puh_sk8@hotmail.com | Symbian Networking & Messaging | 0 | 2006-11-20 18:19 |
| nokia 7210 modem via IR doesn't work ! | oussamaaiadi | PC Suite API and PC Connectivity SDK | 1 | 2003-03-06 11:46 |