我想我在这里遗漏了一些非常明显的东西,但是每个人为 CSV.open 方法输入的第二个参数是什么,在这种情况下是wb",我已经看到其他字母放在这里,但没有人真正解释它的作用.它有什么作用?
I think I'm missing something really obvious here, but what is the second argument that everyone puts in for CSV.open method, in this case its 'wb', I've seen other letter(s) put here, but no one really explains what it does. What does it do?
CSV.open("path/to/file.csv", "wb") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... endruby 文档似乎没有给出任何解释.www.ruby-doc/stdlib-2.0/libdoc/csv/rdoc/CSV.html
The ruby doc doesn't seem to give any explanation. www.ruby-doc/stdlib-2.0/libdoc/csv/rdoc/CSV.html
谢谢!
推荐答案来自 IO 开放模式 文档:
"r" 只读,从文件开头开始(默认模式).
"r" Read-only, starts at beginning of file (default mode).
"r+" 读写,从文件开头开始.
"r+" Read-write, starts at beginning of file.
"w" 只写,截断现有文件为零长度或创建一个新文件进行写入.
"w" Write-only, truncates existing file to zero length or creates a new file for writing.
"w+" 读写,将现有文件截断为零长度或创建一个新文件进行读写.
"w+" Read-write, truncates existing file to zero length or creates a new file for reading and writing.
"a" 只写,如果文件存在,则从文件末尾开始,否则创建一个新文件用于写入.
"a" Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
"a+" 读写,如果文件存在,则从文件末尾开始,否则创建一个新文件用于读取和写作.
"a+" Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
更多推荐
ruby 中 CSV.open() 的第二个参数/参数是什么?
发布评论