You Are Here:

Community: Developer Discussion Boards

#1 Old retrieve data from a file - 2008-08-20, 16:46

Join Date: Jun 2008
Posts: 56
djsid
Offline
Regular Contributor
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
Reply With Quote

#2 Old Re: retrieve data from a file - 2008-08-20, 16:57

Join Date: Feb 2008
Posts: 2,542
Location: Bhavnagar, Gujarat, India
Send a message via Yahoo to gaba88 Send a message via Skype™ to gaba88
gaba88's Avatar
gaba88
Offline
Forum Nokia Champion
Quote:
Originally Posted by djsid View Post
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
hi
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
Reply With Quote

#3 Old Re: retrieve data from a file - 2008-08-20, 16:57

Join Date: Nov 2006
Posts: 186
Location: Pune, india
sagars's Avatar
sagars
Offline
Regular Contributor
Quote:
Originally Posted by djsid View Post
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
your problem is not so much clear to me.. still read following link

this may help u...
Reply With Quote

#4 Old Re: retrieve data from a file - 2008-08-20, 18:18

Join Date: Dec 2007
Posts: 409
Location: Tempe, AZ
Send a message via Yahoo to shubhendra Send a message via Skype™ to shubhendra
shubhendra's Avatar
shubhendra
Offline
Forum Nokia Champion
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.
Reply With Quote

#5 Old Re: retrieve data from a file - 2008-08-20, 23:15

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Quote:
Originally Posted by djsid View Post
3 numbers each row separated with space,
i would like to save the 3 numbers in variables for each row
Hmph,

Code:
(a, b, c) = line.split(' ')
Cheers,

--jouni
Reply With Quote

#6 Old Re: retrieve data from a file - 2008-08-21, 05:45

Join Date: Dec 2007
Posts: 409
Location: Tempe, AZ
Send a message via Yahoo to shubhendra Send a message via Skype™ to shubhendra
shubhendra's Avatar
shubhendra
Offline
Forum Nokia Champion
Oh Thanks Jouni, how can i forget "split".


IDEAS is all they need but still they think only Genius can give them that.
Reply With Quote

#7 Old Re: retrieve data from a file - 2008-08-21, 07:51

Join Date: Sep 2005
Posts: 314
Location: Finland, Helsinki
aaaaapo
Offline
Regular Contributor
Quote:
Originally Posted by JOM View Post
Hmph,
Code:
(a, b, c) = line.split(' ')
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)!". :-)
Reply With Quote

#8 Old Thumbs up Re: retrieve data from a file - 2008-08-21, 14:24

Join Date: Jun 2008
Posts: 56
djsid
Offline
Regular Contributor
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia