I am having diificulty importing a module that i've created in package.
here is my code :
import test.addition._addition
import test.subtraction._subtraction
import test.multiplication._multiplication
class calcul:
def addition(self, a, b):
self.c = _addition(a,b)
print self.c
def subtraction (self, a,b):
self.c = _subtraction(a, b)
print self.c
def multiplication (self, a, b):
self.c =_multiplication (a, b)
print self.c
As you noticed from the first 3 lines of the code, I've stored the module _addition
in a folder called addition and again I stored the addition folder in a folder called test. It is the same for subtraction and multiplication. In each folder, I've created a module __init__
to make sure that it is declared as a packages.
To be even more clearer, below is the code in the module _addition
def _sous_addition(a,b):
return float(a) + float(b)
The problem is that python told me that :
global name '_addition' is not defined
When writing import test.addition._addition
, then the name that is available in your local scope is test
, and you can access the _addition
function using test.addition._addition
. You need to use its full name.
If you want to import the function with the name _addition
into the local scope, you need to write either of these things:
from test.addition import _addition
import test.addition._addition as _addition
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments