I have a folder structure below and I want to import a client from Util1.py in Impl1.py but understand this I can not see how to write an import function I have seen mention of pithonpath but it can not be fully understood how the details are written around it. Any help is appreciated
Some information - I am using Python 3.4. Please tell me what help I can provide to other people to help answer your question.
The proper way to handle it is to pack your project into packages, then use related imports (here are many questions about this, for example:,.).
If you can not reconstruct your code, it may be necessary that the dynamically dump your "other" code in its path.
For example, suppose you are inside Impl1.py
and want to call foo
inside Util1.py
, you can do this:
Obtain parent of #parent import OS, in CSP = os.path.realpath (__ file_) _ range (3): pp = Os.path.dirname (PP) # Add NP to path sys.path.append (os.path.join (PP, 'Youth', 'src')) # import file import Util1 # call function Util1.foo ()
No comments:
Post a Comment