Reputation: 1
I'm learning python and I'm facing this little problem I have created a function that simply reads a file and loads data into a dictionary I have to use this function many times and in different scripts In C i would have created a .h file and a .c file and simply inserted something like include "mylib.h" where I wanted to use that function How can I do something like that in Python?
Upvotes: 0
Views: 44
Reputation: 458
Save the function 'fn' in a module file 'mod.py' Import the module wherever you want to use it with
import mod
...
mod.fn()
or
from mod import fn
...
fn()
Upvotes: 2