I was trying to import
a py file in one of the files.
The folder is A
, and B
and C
are files inside that.
I want to get C
in B
. I tried import C
and from . import C
. None of those worked. Any suggestions?
Asked
Active
Viewed 302 times
0
-
1You don't import a PY file, you import elements defined in that file. Can you be more clear about your file organization, and what you are trying to import? And finally, what error messages are you getting? – John Ladasky Jan 23 '22 at 01:41
-
1It doesn't matter that `C` and `B` are in the same folder. What is relevant is what the current working directory (CWD) is when `B` is executing. How are you running `B`? Also see [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time). – martineau Jan 23 '22 at 02:08
-
@JohnLadasky Hi, Thanks for your response. I figures it out. Thanks for your help. – Wowz Jan 23 '22 at 03:47
-
"You don't import a PY file, you import elements defined in that file." - That might be the more common case, but it's also perfectly normal to import an entire module. It's done all the time, including with the most popular packages in the python ecosytem. – odigity Jun 21 '22 at 13:36