TypeError:'

问题描述 投票:0回答:1

[每当我尝试运行此代码时,它都会得到TypeError:' + =-”的整数

  import cx_Oracle

  conn = cx_Oracle.connect('emu/[email protected]')
  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

python arrays while-loop tuples cx-oracle
1个回答
1
投票

您是否尝试过:

for line in cur:
  (maxID,) = line

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

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

ValueError: too many values to unpack (expected 1)
© www.soinside.com 2019 - 2024. All rights reserved.