ruby 中 CSV.open() 的第二个参数/参数是什么? [英] What is the second parameter/argument to CSV.open( ) in ruby?

查看:47
本文介绍了ruby 中 CSV.open() 的第二个参数/参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我在这里遗漏了一些非常明显的东西,但是每个人为 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"]
  # ...
end

ruby 文档似乎没有给出任何解释.http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html

The ruby doc doesn't seem to give any explanation. http://www.ruby-doc.org/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() 的第二个参数/参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆