By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,760 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,760 IT Pros & Developers. It's quick & easy.

Re: file operations.

P: n/a

aditya shukla wrote:
Guys thanks for your previous help .I have a doubt again

My text file is :-

now this is what happens

'\n' ---? i am not able to understand why is new line character
returned here
Either because your text file starts with a blank line or because
..readline does not work when you open in binary mode. In any case, you
should probably change 'rb' to 'r'.
>>l =x.readline()
>>print l

Also , because of this i am not able to extract the floating point
values ie 0.50,0.50,0.66 respectively
cause when i use the proposed solution given earlier

for line in x:
data.append(float(line[-2])) --i am trying to get the floating
point values from the back

i receive this error message

Traceback (most recent call last):
File "<pyshell#71>", line 3, in <module>
IndexError: list index out of range
If you have a blank line, splitting returns a list of length 0 or 1, so
there is no -2 element. Add something like
if len(line) < 2: raise SomeError(message)
after the split. If you should always have 3 parts, check '==3' and
index to line[1].


Jul 25 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.