Is there a reason why when importing python files, you still need to name the file.function_name?
import, python
Solution
If you wanted to use `my_file.function` by just calling `function`, try using the `from` keyword.
Instead of `import my_file` try `from my_file import *`.
You can also do this to only import parts of a module like so : `from my_file import function1, function2, class1`
To avoid clashes in names, you can import things with a different name: `from my_file import function as awesomePythonFunction`
EDIT: Be careful with this, if you import two modules (`myfile, myfile2`) that both have the same `function` inside, `function` will will point to the `function` in whatever module you imported last. This could make interesting things happen if you are unaware of it.
Problem
I am currently doing a python tutorial, but they use IDLE, and I opted to use the interpreter on terminal. So I had to find out how to import a module I created. At first I tried ``` import my_file ``` then I tried calling the function inside the module by itself, and it failed. I looked around and doing ``` my_file.function ``` works. I am very confused why this needs to be done if it was imported. Also, is there a way around it so that I can just call the function? Can anyone point me in the right direction. Thanks in advance.