当我将Python从2.7版本升级到3.8时出现以下错误 [英] When I am upgrading Python from version 2.7 to 3.8 getting below error

查看:95
本文介绍了当我将Python从2.7版本升级到3.8时出现以下错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3.8版本中的错误:

失败:变量'$ {Trans_id_temp} [0]'是映射,不可下标,因此正在访问项目从中不可能为 0。要将 [0]用作文字值,需要像斜杠[0]一样转义。

FAIL : Variable '${Trans_id_temp}[0]' is map, which is not subscriptable, and thus accessing item '0' from it is not possible. To use '[0]' as a literal value, it needs to be escaped like 'slash [0]'.

版本3.8

从$ {Trans_Id_temp}返回对象= [< 0x000001CC16130460处的地图对象,< 0x000001CC16130400处的地图对象],< 0x000001CC16130040处的地图对象,< 0x000001CC161300160处的地图对象,,< map <0x000001CC16130AF0&>处的地图对象,<0x000001CC16130A90>处的地图对象,<0x000001CC16130A30处的地图对象>] [0] [0]

Return object from ${Trans_Id_temp} = [<map object at 0x000001CC16130460>, <map object at 0x000001CC16130400>, <map object at 0x000001CC16130040>, <map object at 0x000001CC16130160>, <map object at 0x000001CC16130AF0>, <map object at 0x000001CC16130AC0>, <map object at 0x000001CC16130A90>, <map object at 0x000001CC16130D30>][0][0]

版本2.7

$ {Trans_Id_temp} = [[u'842.0']]

${Trans_Id_temp} = [[u'842.0']]

如何解决此问题,任何人都可以帮助我

How to solve this and anyone can help me to resolve?

Wait Until Keyword Succeeds    5m   5s    Check If Exists In Database   select * from ompgmd.ompg_prov_trns where CONF_ID='${PE_ConfirmationNumber.strip()}'
${Trans_Id_temp}=    Query    select TRANS_ID from ompgmd.ompg_prov_trns where CONF_ID='${PE_ConfirmationNumber.strip()}'
Log    ${Trans_id_temp}[0][0]
Set Global Variable     ${Trans_Id}    ${Trans_Id_temp}[0][0]


推荐答案

谢谢大家的评论,我才这样解决,希望这对以后使用Python 3.8版本面临同样问题的人们有所帮助。

Thank you all for your comments and I just got resolved in this way, hope this will help in future for the people facing same kind of issue with Python 3.8 version.

在Python3之前,map()用于返回一个列表,其中结果列表的每个元素都是函数func应用于列表或元组 seq的相应元素的结果。使用Python 3,map()返回一个迭代器。

Before Python3, map() used to return a list, where each element of the result list was the result of the function func applied on the corresponding element of the list or tuple "seq". With Python 3, map() returns an iterator.

因此,如前所述,而不是列表,它返回升级版本的对象,而我只是在DB部分中做了如下更改,

So as mentioned instead of list it returns object in upgraded version and I just changed as below in DB part,

版本2.7

def query(self, select_statement):
        """
        Executes the select_statement as SQL command and return query result.\n
        Example usage:
        | @{queryResult} | Query | SELECT * FROM NLS_DATABASE_PARAMETERS |
        | Log Many | @{queryResult} |
        """
        cursor = None
        try:
            cursor = self.connection.cursor()
            self.__execute_sql(cursor, select_statement)
            all_rows = cursor.fetchall()
            i = 0
            for x in all_rows:
                all_rows[i] = map(lambda s: str(s).decode("utf-8") if s else '', x)
                i += 1
            return list(all_rows)
        finally:
            if cursor:
                self.connection.rollback()

版本3.8

def query(self, selectStatement, sansTran=False, returnAsDict=False):
        cur = None
        try:
            cur = self.connection.cursor()
            logger.info('Executing : Query  |  %s ' % selectStatement)
            self.__execute_sql(cur, selectStatement)
            allRows = cur.fetchall()

            if returnAsDict:
                mappedRows = []
                col_names = [c[0] for c in cur.description]

                for rowIdx in range(len(allRows)):
                    d = {}
                    for colIdx in range(len(allRows[rowIdx])):
                        d[col_names[colIdx]] = allRows[rowIdx][colIdx]
                    mappedRows.append(d)
                return mappedRows

            return allRows
        finally:
            if cur:
                if not sansTran:
                    self.connection.rollback()

我已经创建了一个名为mappingRows的空列表,并向其添加了[] []对象。这对我有用。

I have created empty list as mappedRows and appended [] [] object to it.This worked for me.

这篇关于当我将Python从2.7版本升级到3.8时出现以下错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆