ruby 中 CSV.open() 的第二个参数/参数是什么?

编程入门 行业动态 更新时间:2024-10-28 05:20:29
本文介绍了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 文档似乎没有给出任何解释.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() 的第二个参数/参数是什么?

本文发布于:2023-10-24 02:50:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   第二个   ruby   CSV   open

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!