Reputation: 187
Because the main file was getting quite long, I decided to split my code into two files, one containing all functions (here called common_functions.py
) and one containing classes and methods, the later importing the former. The issue is, I would like to import those functions using
from common_functions import *
as I do not need a prefix for the function inside and because they are quite numerous. Also, although not important, this allows me not to have to repeat importing packages in the class file. The issue is, spyder does not identify the inside of the imported file, resulting in warnings everywhere as shown below, although the code is executed normally.
So my question is, is there a way to remove these warning, either by explaining spyder how to get to the packages and functions of common_functions.py
, or to organising the code in a different way ?
Upvotes: 0
Views: 526
Reputation: 8634
Spyder uses pyflakes under the hood for the real-time code analysis in the editor pane. Pyflakes doesn't have the capability to interpret wildcard import statements (i.e. it won't retrieve all the names that are actually imported by a wildcard import). Hence the warning messages about undefined names that you're getting.
I would recommend to avoid wildcard imports altogether in your code files. Though wildcard imports are valid python code, they are widely considered a bad practice in most situations (see here and here for more detailed explanation). If you replace from common_functions import *
with for example import common_functions as cf
, then the prefix that you have to use is minimal in length.
Upvotes: 2