Import code from another source (python) (windows 7,8,10) -


i having problem. 2 different codes in same directory, cannot following:

from py_file1 import *

considering py_file2.py , directory looks this:

new folder >     py_file1.py     py_file2.py 

i want able this:

#file1 contents: def a():     print("a function in file1.") 

and this:

#file2 contents py_file1 import * a() 

and when run in interpreter, there no importerror.

>>> function in file1. >>> 

it looks you're current directory not same files stored. latter not in path.

you should put modules somewhere in search path of python or add directory files in search path:

from sys import path path.insert(1, "path/to/lib") py_file1 import * a() 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -