user33338
user33338

Reputation: 1

personal libraries C-like in Python

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

Answers (1)

sgauria
sgauria

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

Related Questions