1
我做了這個代碼在python:Robot Framework:如何讀取csv文件中的隨機行並使用這些值?
import csv
import random
class RandomRowFromCsv (object):
ROBOT_LIBRARY_SCOPE = 'Global'
def __init__(self):
print 'Read Random Cell Value in CSV File'
def read_random_row(self,filename):
csv_userinfo=[]
auserinfo={}
with open(filename,'rb') as csvfile:
reader=csv.DictReader(csvfile)
csv_userinfo=list(reader)
lengthofcsv=len(csv_userinfo)
position=random.randrange(1,lengthofcsv)
auserinfo=RandomRowFromCsv(*csv_userinfo[position])
return auserinfo.username
return auserinfo.password
但我不能得到的值,並在機器人框架的腳本,讓他們的價值觀,有人能幫助我嗎?
你會收到錯誤信息嗎?顯示有問題的完整錯誤消息(Traceback)。你可以用'RandomRowFromCsv(argument)'作爲參數,但是你不需要參數就可以聲明'__init __(self)'。你如何執行'read_random_row()'? (返回auserinfo.password') – furas
AttributeError:'list'對象沒有屬性'username'@furas – andrembg
顯示完整的錯誤信息(Traceback)。看到「完整」和「有問題」的詞語! – furas