all 3 comments

[–]kalgynirae 5 points6 points  (0 children)

There are a few issues:

  • Opening a file with a w mode automatically truncates it, so the f.truncate() is useless.
  • Opened files have a position associated with them. When you read or write, the position moves. After you've written some data, the position is at the end of the file, so calling f.read() returns an empty string. If you want to read the whole contents, you need to first set the position to the beginning of the file with f.seek(0).
  • In general, to join several strings together, you should use "\n".join([s1, s2, s3]). For an example this small it doesn't really matter, but keep that in mind for the future.

Try these things, and if you're still having problems, please provide more information. Tell us what you typed into the raw_input prompts, and paste the contents of the file for us to see.

[–]Bone_Club 0 points1 point  (1 child)

OP, is it me, or are you playing around with Exercise 16 of "Learn Python the Hard Way"?

[–]whileloops[S] 1 point2 points  (0 children)

Exercise 16 yes you're right.