jl487
May 10, 2010, 10:13pm
1
cat is such a simple and useful command in UNIX. I was wonder if python had any equivalent.
More specifically, I have a .txt file that I would like displayed from a python script.
Is there a similar command besides "print?" When I try to use the print command, the text is formatted differently (one long string with "\n")
Thanks!
I'm a totally py n00b, but I was curios and after googling for a few minutes I found out following code will do the thing:
$ cat readfile.py
#!/usr/local/bin/python
f = open("data.dat", "r")
text = f.read()
print text
f.close()
$
You probably used readlines which puts the output in an array or something
jl487
May 10, 2010, 10:56pm
3
thanks. I did find a similar code, but yours is definitely easier to read. And you're right, I was using .read/.readlines which printed everything out in an array.
Thank you so much for your help!