I’m having a hard time importing my functions. This is the error message i get File “c:/Users/Desktop/Python Files/test.py”, line 1, in
from addfunction import add_num
ImportError: cannot import name ‘add_num’ from ‘addfunction’ (c:\Users\Tolerm\Desktop\Python Files\addfunction.py)
I have no trouble importing other fuctions.
Visual Code Studio is the text editor i’m using
Without seeing the code, I can only guess that you’ve spelled one of them differently.
When you look at the
addfunction.py file that is in that same folder, do you see a function named
add_num? Is it at the top level of the code (not indented inside another function or a class), and spelled exactly that way (including capitalization and the underscore)?
If you try
import addfunction instead, does that work? When you do that, what result do you see if you then try
dir(addfunction)? How about
'add_num' in dir(addfunction)?
Can you show an example that does work? If you carefully study the working example, can you see a difference between that and the non-working example?