Welcome to the Treehouse Community
Looking to learn something new?
[PYTHON] Displaying text length instead of the actual text.
Here is my code: I'm trying to display the 5 oceans, each in a new line, but when I run it, it displays the character length for each ocean, and not the actual text.
>>> oceans = ['Pacific', 'Atlantic', 'Indian', 'Southern', 'Arctic'] >>> with open('oceans.txt', 'w') as f: ... for ocean in oceans: ... f.write(ocean) ... 7 8 6 8 6
Any idea why it is doing this?
Chris FreemanTreehouse Moderator 67,989 Points
This is correct behavior:
f.write(string) writes the contents of string to the file, returning the number of characters written. (see docs: methods of file objects)
The file is getting written with “PacificAtlanticIndianSouthernArctic”
Post back if you need more help. Good luck!!!