如果条件

发布于 2025-01-24 14:48:14 字数 922 浏览 3 评论 0 原文

我正在尝试将API查询响应插入到SQL Server数据库中。在特定字段上,我需要检查查询响应中字段的值是对还是错误,如果是false,则需要插入“ f”,如果它是真的,我需要在DB中插入“ T”字段,

    cursor = sqlconn.cursor()
    for index,row in roomsDF.iterrows():
        cursor.execute("INSERT INTO SurplusMouse.RM_Room(ROOMID, NAME, DESCRIPTION, SHIPPING_FREEZE, UPDATEDNAME)\
                                    values(?,?,?,?,?)"

                        ,row['id']
                        ,row['name']
                        ,row['description']
                        , if row['shippingFreeze'] == false:
                             'F' 
                         else: 
                             'T'
                        ,row['shippingFreeze'].split(' ', 1)
                    )

我看到这里的两个错误在 cursor.execute上一个错误(“ as ”(“没有关闭,另一个问题是 eresence Expression pylance pylance erroron the 如果

I am trying to insert the API query response in to the SQL server database. On a particular field I need to check if the value of the field on the Query response is true or false , if it is false I need to insert 'F' if its true I need to insert 'T' a field in DB

    cursor = sqlconn.cursor()
    for index,row in roomsDF.iterrows():
        cursor.execute("INSERT INTO SurplusMouse.RM_Room(ROOMID, NAME, DESCRIPTION, SHIPPING_FREEZE, UPDATEDNAME)\
                                    values(?,?,?,?,?)"

                        ,row['id']
                        ,row['name']
                        ,row['description']
                        , if row['shippingFreeze'] == false:
                             'F' 
                         else: 
                             'T'
                        ,row['shippingFreeze'].split(' ', 1)
                    )

I see two errors here one on the cursor.execute(" as "(" was not closed and another issue is Expected expression Pylance erroron the if . This is my first Python script and not sure if I am missing something any help is greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2025-01-31 14:48:14

在我看来,您正在混合两个不同的概念。您需要分裂和征服。

  1. 检索数据,并为每个值创建一个变量。

      id = row ['id']
     名称=行['名称']
     shippingfreeze ='t'如果行['shippingfreeze'] else'f'
     
  2. 然后,创建execute命令。确保运输属性正确地格式化为布尔值。

关于

L.

It seems to me you are mixing two different concepts. You need to divide and conquer.

  1. Retrieve the data, and create a variable for each value.

     id = row['id']
     name = row['name']
     shippingFreeze = 'T' if row['shippingFreeze'] else 'F'
    
  2. Then, create the execute command. Make sure that the shippingFreeze attribute comes correctly formatted as boolean.

Regards

L.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文