iT邦幫忙

0

TypeError: '<' not supported between instances of 'NoneType' and 'str'

  • 分享至 

  • xImage

小弟是剛接觸sql,以前也不常使用python的sql語法,在使用上時遇到了以下的問題,想請各位大神的協助,以下是我的code,是用於查詢資料庫欄位有的選項:
https://ithelp.ithome.com.tw/upload/images/20210902/20141403VvKSNbvssx.png
但出現了的錯誤:
https://ithelp.ithome.com.tw/upload/images/20210902/20141403mjvIlwR8PA.png
我發現會出現此error的原因是她除了抓到選項,還會多抓到none:
https://ithelp.ithome.com.tw/upload/images/20210902/20141403NNwkGcIzVF.png
而我在網上查詢了解決方法並加入他的code,如下:
https://ithelp.ithome.com.tw/upload/images/20210902/20141403LpIEmJineF.png
但就出現了新的error:
https://ithelp.ithome.com.tw/upload/images/20210902/20141403At3NwcCJUD.png
到底該如何處理,HELP

看更多先前的討論...收起先前的討論...
你的result在第一次就變成x[0]的list了吧?
所以才會出現not subscripttable
第一次的x[0]改成x看看呢?
請問你是說result = [x[0] for x in cursor.fetchall()]這一段嗎?我剛剛是了但會出現
AttributeError: 'set' object has no attribute 'sort'
這是因為你23行是用{}裝
24行又呼叫了.sort()
.sort()是給[]呼叫的
撰寫的時候同一個變數盡量不要型態變來變去
這樣容易亂掉
成功了!!!感謝你~
obarisk iT邦研究生 2 級 ‧ 2021-09-03 09:53:40 檢舉
先在 sql 把 NULL 丟掉吧... sort 也可以在 sql 裡面做

取整塊資料 直接用 pandas read_sql 比較方便. 程式看起來比較乾淨
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答