【发布时间】:2016-11-01 07:19:16
【问题描述】:
我的python经验很少,perl知识为零,但我需要将连接MySQL服务器的perl代码翻译成python。
在perl子程序中,在标准连接动作之后,出现的代码是:
my @tmp = @{$dbh->selectall_arrayref( $sql )};
my @types;
foreach my $t (@tmp) {
push @types, @$t[0];
}
return @types;
其中 $sql 是 MySQL 选择查询。我会在 python 函数中做的是:
cursor = conn.cursor()
cursor.execute( sql )
tmp = cursor.fetchall()
types = list( len( tmp ) )
for item in tmp :
types.append( item[0] )
return types
我的问题是 @$t[0] 包含什么,它是否等同于 tmp 中的 item[0]?
谢谢!
【问题讨论】: