I am running this script (parent.py)
import sys
sys.path.append('/python/loanrates/test')
import test2
test2
from this directory:
D:\python\loanrates\Parent
Which opens this script (test.py)
import json
data = 'ello world'
with open( 'it_worked.json', 'w') as f:
json.dump(data, f)
From this directiory
D:\python\loanrates\test
When I run parent.py which consequentially runs test.py I want the json.dump to save in D:\python\loanrates\test' currently it saves inD:\python\loanrates\Parent`
EDIT: I have made the following edits:
This is now the child file:
import json
def main():
data = 'ello world'
print data
with open( 'D:/python/loanrates/test/it_worked.json', 'w') as f:
json.dump(data, f)
if __name__ == '__main__':
main()
And this is my parent:
import sys
import thread
sys.path.append('/python/loanrates/test')
import test2
thread.start_new_thread(test2.main())
I get this error:
TypeError: start_new_thread expected at least 2 arguments, got 1
What is the second argument i need to put in ?
implib or__import__for absolute paths.parentnot test, since you're executing out ofparentand not test. Also obviously you can append to system path and I guess there's technically not anything wrong with it. But my experience working with custom imports is that it's best to use the import libraries that can handle custom namespaces, global variables uniquely for that library/module.