TypeError:“int”和“tuple”实例之间不支持“<”

2024-10-02 00:24:44 发布

您现在位置:Python中文网/ 问答频道 /正文

每当我尝试运行此代码时,它都会得到TypeError:“<;”“int”和“tuple”错误实例之间不支持,因为它返回int并另存为tuple,并且当我尝试分配返回值时 它的作用就好像它不是一个整数,您不能对它使用“<;>;+=-”

  import cx_Oracle

  conn = cx_Oracle.connect('emu/emu@127.0.0.1')
  cur = conn.cursor()
  cur.execute("select max(locationid) from location")
  for line in cur:
      maxID = line
  IDofcity = 1
  while IDofcity < maxID:
      cur.execute(f"select city from location where locationid='{IDofcity}'")
      for row in cur:
          Nameofcities = ['']
          Nameofcities.append(row)

  IDofcity += 1

  print(Nameofcities)

  cur.close()
  conn.close()

守则及;错误

enter image description here


Tags: fromltexecute错误connselectintoracle
1条回答
网友
1楼 · 发布于 2024-10-02 00:24:44

您是否尝试过:

for line in cur:
  (maxID,) = line

这使得maxID引用元组中的值,而不是元组本身

如果元组中有1个以上的项,您将得到:

ValueError: too many values to unpack (expected 1)

相关问题 更多 >

    热门问题