If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Read File

Am new to python so I decided to take some notes in .txt files and thought it would be a good idea if I had program that could read them! So I set out to do this. All is well except whenever there is a new line in the text file python prints "\n" instead of taking a new line.
This is my code:

name=raw_input("Which file would you like to read?")

second=".txt"

name = "%s%s" % (name,second)

file = open(name)

for line in file:
print line,

Text File:
Python is great
I love python
but why is it doing this?

Result:
Python is great \n I love python \n but why is it doing this?
What am I doing wrong!? Thanks

^ Well, nobody can tell you what's wrong with what you're doing if nobody can see it. But you should probably read up on read() and readlines(); they're very useful when you're working with text files.

Mac

Done some more research and found that it doesn't work on mac os x because of some GNU licence agreement. I tried my program on linux and it worked fine. Am now looking at how to get it to work on the mac..

file.readline() does not work on mac for some strange reason!
Does anyone know how to solve this?

Uhm. Put an s in file.readline? Like: file.readlines(). You should also catch the result in a variable because readlines() is going to return a list. But again, what are you trying to do and how are you trying to do it?