I'm doing my python assignments using PyCharm. I have created folders like "Assignment 01", "Assignment 02" and so on. In each of the assignment folders, I have 2 python files. "Helper.py" and "Demo.py". In "Demo.py", I have to import the Helper
file. I do that using
import Helper
But PyCharm doesn't recognize this unless I mark the directory containing the Helper
files as Sources Root
. So, I marked my directory "Assignment 01" as Sources Root
. All is fine. Now, I started with "Assignment 02". In "Demo.py" of "Assignment 02", I imported Helper
. This imports Helper
from "Assignment 01" and not "Assignment 02". Even if I mark "Assignment 02" as Sources Root
, PyCharm still refers to "Helper.py" from "Assignment 01". How to make PyCharm refer to "Helper.py" in the same folder?
Note: I don't want to open different Assignments as different projects. I would like to have everything as a single project.
Any other suggestions, conventions, best practices are also welcome. Thanks!
You can set the root project folder as the Sources Root
.
After that, to import Helper from Assignment01, simply do import Assignment01.Helper
, and import Assignment02.Helper
for Assignment02.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.