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 =
If you're open to using libraries, try installing forked-path (with either easy_install or pip).
Then you can do:
from path import path
s = path(filename).bytes()
This library is fairly new, but it's a fork of a library that's been floating around Python for years and has been used quite a bit. Since I found this library years ago, I very seldom use os.path
or open()
any more.