输入文件看起来像:
狗,白,男 猫,紫色,女性 老鼠,灰色,男性
我想逐行检查并处理这些数据。
File.open("animals.csv")
while file has next line
currentline = array with each cell being an entry in the array
if currentline[0] == dog
put "dogs are cool"
end
put "your animal is a " + currentline[0]
end
Run Code Online (Sandbox Code Playgroud)
你明白了,对吧?我想用 ifs 和诸如此类的东西来操作数据行,并在最后将其全部打印出来。
谢谢
Illegal quoting in line 1. (CSV::MalformedCSVError)
当我尝试读取使用Selenium WebDriver下载的CSV时,我得到了一个.
CSV.foreach( "foo.csv" ) do |row|
# anger :(
end
Run Code Online (Sandbox Code Playgroud)
但是当我复制内容并将其粘贴到一个新文件并再次保存时,它可以正常工作:
CSV.foreach( "bar.csv" ) do |row|
# works fine
end
Run Code Online (Sandbox Code Playgroud)
这是有问题的CSV的前5行,如果它有帮助......
"Name","W","L","ERA","GS","G","SV","IP","H","ER","HR","SO","BB","WHIP","K/9","BB/9","FIP","WAR","playerid"
"Craig Kimbrel","5","1","1.79","0","65","35","65.0","42","13","4","95","19","0.95","13.16","2.65","1.84","1.7","6655"
"Aroldis Chapman","2","1","1.93","0","30","27","30.0","18","6","2","47","12","0.99","14.24","3.56","2.22","0.6","10233"
"Greg Holland","5","2","2.39","0","65","34","65.0","47","17","5","83","21","1.05","11.53","2.95","2.48","1.3","7196"
"Kenley Jansen","5","2","2.16","0","65","32","65.0","46","16","6","86","19","1.00","11.97","2.64","2.51","0.9","3096"
Run Code Online (Sandbox Code Playgroud)
我无法找到或想出一种方法来正确读取原始的,下载selen的CSV.任何人遇到这个或对我的数据可能出错的地方有任何想法,或者我如何以编程方式解决这个问题?
谢谢!
现在,我正在使用<body onload="function">
,它根据所关注的元素来更改页面上的某些文本。它工作正常,但是每次焦点改变时(或者甚至每次单击页面的任何部分时,我都需要运行我的网站)。
当前代码如下:
<body onload="changeText()">
<script>
function changeText(){
function here;
}
</script>
<p>This is where text changes based on the function</p>
Run Code Online (Sandbox Code Playgroud)
谢谢!