In Ruby you can read from a file using s = File.read(filename)
. The shortest and clearest I know in Python is
with open(filename) as f:
s =
contents = open(filename)
This gives you generator so you must save somewhere the values though, or
contents = [line for line in open(filename)]
This does the saving to list explicit close is not then possible (at least with my knowledge of Python).
Slow, ugly, platform-specific... but one-liner ;-)
import subprocess
contents = subprocess.Popen('cat %s' % filename, shell = True, stdout = subprocess.PIPE).communicate()[0]
Simple like that:
f=open('myfile.txt')
s=f.read()
f.close()
And do whatever you want with the content "s"