3 ms·
Not sure about the Python ones, but the Ruby read/write file examples aren't quite fully done/correct here: # Equivalent of file_put_contents() in PHP # Th
by getsat 14y ago
Not sure about the Python ones, but the Ruby read/write file examples aren't quite fully done/correct here:
# Equivalent of file_put_contents() in PHP
# This could also be used for appending if the correct mode is specified.
File.open("filename", "w") { |f| f.write("some data") }
# Equivalent of file_get_contents() in PHP
some_var = File.read("filename")
- codesuela 14y agoPython: with open("filename", "r") as a_file: contents = a_file.read()
- jeltz 14y agoRuby 1.9.3 added File.write("filename", "some data").
- getsat 14y agoCool. Didn't know that. Thanks.
- egonschiele 14y agoI guess I should have specified "where f is a file handle": f = File.open("foo", "r") f.read f = File.open("foo", "w+") f.write(x)