On 02/02/2014 04:08 AM, adrian wrote:
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
Do you realise you are calling two different very objects, a list of nums and a
file, with the same name 'lab3int'?
d
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor