global … is not defined python

后端 未结 3 1330
有刺的猬
有刺的猬 2021-01-29 12:24

I need to read some words text by text in python, and I am getting this error. \"NameError: global name \'wordList\' is not defined.

i=0
with fitxer as f:
    fo         


        
3条回答
  •  情歌与酒
    2021-01-29 12:57

    You haven't defined wordList before you try to use it in your loop or return it.

    Try adding wordList = [] below i=0 to declare wordList as an empty list.

    Also, you should use wordList.append(i) to add your word this list.

提交回复
热议问题