我从DB获取数据并得到了这个元组。我正在使用下面的代码将元组转换为list.but输出即将成为索引。喜欢
<?php
require_once './config/config.php';
$msg = "";
use PHPMailer\PHPMailer\PHPMailer;
if (isset($_POST['submit'])) {
$f_name = $db->real_escape_string($_POST['f_name']);
^ in the line of code above is where the error comes
以上代码返回此
${Rows} [('3/6/2018', '16', '8', '50.00', '3024', '1349', '44.61'), ('3/5/2018', '16', '9', '56.25', '3024', '2114', '69.91'), ('3/4/2018', '16', '9', '56.25', '3024', '2224', '73.54')]
${RowWise} create list
: FOR ${j} IN RANGE 0 7
\ ${row}= Evaluate [x[${j}] for x in ${Rows}]
\ append To list ${RowWise} ${row}
Log List ${RowWise}
我想要这样的东西
[('3/6/2018','3/6/2018','3/6/2018','3/6/2018','3/6/2018','3/6/2018'), ('16','16','16','16','16',)....]
你能帮我吗?
注意:使用python iam能够获得解决方案。但试图在机器人框架中实现。
答案 0 :(得分:1)
这是一个可以使用列表理解的好例子。
我们可以将元组转换为列表
x = list((1,2))
为您的例子
x = [('3/6/2018', '16', '8', '50.00', '3024', '1349', '44.61'), ('3/5/2018', '16', '9', '56.25', '3024', '2114', '69.91'), ('3/4/2018', '16', '9', '56.25', '3024', '2224', '73.54')]
x = [list(i) for i in x]
print(x)
[[&#39; 3/6/208&#39;,&#39; 16&#39;,&#39; 8&#39;,&#39; 50.00&#39;,&#39; 3024&#39;,&#39; 1349&#39;,&#39; 44.61&#39;],
[&#39; 3/5/2018&#39;,&#39; 16&#39;,&#39; 9&#39;,&#39; 56.25&#39;,&#39; 3024&#39; ,&#39; 2114&#39;,&#39; 69.91&#39;],
[&#39; 3/4/2018&#39;,&#39; 16&#39;,&#39; 9&#39;,&#39; 56.25&#39;,&#39; 3024&#39; ,&#39; 2224&#39;,&#39; 73.54&#39;]]
使用提供的答案How to convert a tuple in robot framework into list
我们可以将此更改为
${Row 1} Evaluate [list(x) for x in $id]