Python ERROR ! argument after * must be an iterable, not int

內容說明

記錄我在學習 Python 路上遇到的坑,並將以補足。

Python ERROR ! argument after * must be an iterable, not int

這問題主要是在講例如使用 threading 套件時,可能會遇到的問題。

threading 套件而立,args 不可以是一個數字,就算 function 的值只需要一個參數,也必須要用 tuple(或可迭代的 object),此指令才允許被執行。

通常是語法規定,原因可能要問當初設計這樣的用意XD。

正確寫法

使用正確寫法後,相信就能執行成功了。

1
threading.Thread(target=function, args=(1,))

錯誤寫法

1
threading.Thread(target=function, args=1)

參考連結

_reverse_with_prefix() argument after * must be an iterable, not int
TypeError: start() argument after * must be an iterable, not int [duplicate]

心得

Python 真的很方便,但即使再方便的程式語言也必須合乎套件要求才有辦法正常執行,只有學會正確的使用方式才可以完整的操作 Python,一起加油吧!

  • 版權聲明: 本部落格所有文章除有特別聲明外,均採用 Apache License 2.0 許可協議。轉載請註明出處!
  • © 2020-2024 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV: