[Tutor] sorting and writing to data file
adrian
asanch505 at hotmail.com
Sun Feb 2 04:08:25 CET 2014
Hello community,
Newbie here. I have a data (.dat) file with integers (2,9,1,5,7,3,9) in
it just as shown.
My instructions are to sort the numbers and rewrite them back to the
data file.
*here is my code:**
*
lab3int=[2,9,1,5,7,3,9]
lab3int.sort()
print(lab3int)
lab3int=open('lab3int.dat','w')
lab3int.write()
lab3int.close()
*here is my error message:*
[1, 2, 3, 5, 7, 9, 9]
Traceback (most recent call last):
File "lab3int.py", line 5, in <module>
lab3int.write()
TypeError: function takes exactly 1 argument (0 given)
I know that it is telling me that my error is in line #5. If I put
anything in the () for lab3int.write function, then that appears in my
data file. however, I am looking to just put the re-sorted integers
back into the data file without having to manually type each integer
manually. Is there something that i can put into the lab3int.write() to
make that happen?
Hope my problem is clear, Thanks people
ATS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140201/1a1ee289/attachment.html>
More information about the Tutor
mailing list