Thursday, 13 April 2017
python - Pythonic way to make subdirectories available to other subdirectories in my project
Answer
How do I structure subdirectories in a python project, and make the code therein available to other subdirectories within the same project?
Example of what I'm finding difficult:
root/
+--- __init__.py
+--- foo/
+--- __init__.py
+--- foo.py
+--- test/
+--- foo_test.py
I have tried to use relative imports (as suggested in this SO answer)
In foo_test.py:
#!/usr/bin/python
from ... import foo
Attempting to run this from the command line:
$ chmod +x ./foo_test.py
$ ./foo_test.py
I get the following error:
Traceback (most recent call last):
File "./foo_test.py", line 3, in
from ... import foo
ValueError: Attempted relative import in non-package
Question:
What is the pythonic way to make foo available to foo_test and other subdirectories which sit alongside foo?
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
Iv'e read a lot of posts both in stackoverflow and other websites talking about web security. Such as salting encrypting etc. ...
-
System.out.print("Name : "); String name = in.nextLine(); System.out.print("Age : "); int age = ...
-
In K-PAX , there are two possible explanations: Prot is crazy. He is truly an alien. There are facts that indicate 1, but also 2. Examples: ...
No comments:
Post a Comment