I want to import a function from another file in the same directory.
Sometimes it works for me with from .mymodule import myfunction but sometimes I get
Whenever you get an error produced by the interpreter or compiler read it carefully. The error message says all about the cause of the encountered error in a nutshell. You are having an ImportError in this case. As you’ve mentioned, you are trying to import a user-defined function from another file within the same directory.
Let me give you an example: https://kodlogs.com/38948/importerror-attempted-relative-import-with-no-known-parent-package
I also learnt that from there, Hope that helps.