私は、CSVファイル内の行を読み取るためのpythonでこのコードを作った:Robotframework:csvファイルのランダムな行を読み込むには?
import csv
class CsvLibrary(object):
ROBOT_LIBRARY_SCOPE = 'Global'
def __init__(self):
print 'Read Cell Value in CSV File'
def read_cell_value_by_row(self,filename,rownumber):
#read an existing csv file
userdata=[]
user={}
with open(filename,'rb') as csvfile:
#read csv file as dictionary object
reader=csv.DictReader(csvfile)
#read and store it as list of dictionary items
userdata=list(reader)
#get specific list item as a dictionary object
user=userdata[rownumber-1]
#return the dictionary object
return user
はその後robotframeworkに、私はこのスクリプトを実行します。
${row_number}= Convert To Integer 1
${user_info}= read_cell_value_by_row UserInfo.csv ${row_number}
${username} Get From Dictionary ${user_info} username
Log ${username}
${password} Get From Dictionary ${user_info} password
Log ${password}
Input Text ${login_username_textbox} ${username}
Input Text ${login_password_textbox} ${password}
をしかし、私は、私は読むことができるかわかりませんCSVファイルのランダムな行、誰かが私を助けることができますか?
同じpythonファイルでは、単にキーワードとして使用できる「get_random row」メソッドを記述するのはなぜですか?ゼロとデータの長さの間の乱数を生成し、これをインデックスとして使用して行を返します。 –