Mostly Linux & Python syntax notes and hyperlinks.

Monday, January 11, 2010

python: import

Here's a good link that explains how to use import.

If I have one file in the directory with only one function that I want to use in another file, I think it's clearer to say this at the top of the other python file:
from my_one_function_file import my_one_function
Then if I stop using that function, I know I can get rid of the import statement. When I look at the import statement, I know exactly why it is there.

The link recommends always using "import", which would mean:
import my_one_function_file
then calling my_one_function via
my_one_function_file.my_one_function()
In general, this recommendation does look like wise practice. It's more object-oriented.

No comments:

Post a Comment