Home > Software engineering >  Python function from imported file shows as undefined
Python function from imported file shows as undefined

Time:10-07

I have a moveslist.py file with function movesSelection and a main.py file. Within my main.py, I've made sure that my variables are set to global and I had another function makeNewChar. Within makeNewChar, I'm trying to call movesSelection but I get "NameError: name 'movesSelection' is not defined.

Since my moveslist.py uses some global variables from main, I imported main into the file. For my main.py, I did from moveslist import *. I also tried import movesList and from moveslist import movesSelection. All of those threw back errors.

How can I use movesSelection within my main.py?

CodePudding user response:

There may be a few different reasons but some of the most common are having a file with the same name or likely the file you are looking for is in another directory so i will show you my correct here

##Include file extension and move the file with the folder in the correct space
import movesSelection.py

CodePudding user response:

Add "from moveslist import movesSelection" into makeNewChar.
You do not have to add the .py suffix when you import.

  • Related