Stupid Question -> importing modules
已回答
I am learning python. I have a project with a bunch of py files
I just built a class and want to import the module. Both files are in the Project ~/PycharmProjects/untitled
File ch10classes.py
File msdie.py
I want to import msdie.py into ch10classes.py
Under settings -> Build -> Console -> Python Console: Add content roots to PYTHONPATH and Add Source roots to PYTHONPATH are both selected.
What else am I doing wrong. Nothing else is configured under Environment excelt Python interpreter path -> Project Default (Python 3.5.2 (/usr/bin/python3.5))
请先登录再写评论。
Hello! Could you please attach a screenshot that shows the problem? Thank you.
I dont think there is a problem. I just dont know how to do it. Built a module want to import to call in another file.
Hi Sparkis! Doesn't simple import works?
that is how it should work. How do I tell pycharm that the file I want to import is in the same dir as the py I am referencing it by.
It should work by default if it's a project root, could you share a whole project with us please?
Do you set the file to be imported as Project Rool or all files within the project? And how would you do it.
I can make the project DIR Sources,Excluded, Templates, REsources....
In the terms of PyCharm, content is a collection of files with which you are currently working, possibly organized in a hierarchy of subfolders. The folder which is the highest in this hierarchy is called content root folder or content root for short. A project has at least one content root folder, by default it is the project folder itself.
Please check the screenshot, where `test` is a project root:
The import is gray colored because Pycharm detects unused import statement. Do you have the same result? If no, which one? could you please attach a screenshot with it?