import - Python Nameerror after importing file -


i'm learning python 3.3 first time , in tutorial have own module , import them. problem here if import worked, nameerror depending of method use import it. here 2 codes import:

from package.fonctions import table table(5) # appel de la fonction table  # ou ... import package.fonctions fonctions.table(5) # appel de la fonction table 

here code supposed call:

def table(nb, max=10):     """fonction affichant la table de multiplication par nb de     1 * nb jusqu'à max * nb"""     = 0     while < max:         print(i + 1, "*", nb, "=", (i + 1) * nb)         += 1 

the first import method work, not second. tells me name "fonctions" not defined, import worked , first method worked too.

in tutorial, both method work, me doesn't if copy-paste code. want understand why.

import package.fonctions doesn't define fonctions name. enables call package.fonctions.table(5) instead.

to enable fonctions.table(5), use from package import fonctions.


Comments