Is it possible in python to define functions outside of a programs main namespace and add them for easy access like a .h file in c?
I don't want to really define my own PyObject. I want to have functions available for use within a program, but I don't have a need for class instances and don开发者_运维问答't want to prefix the function call with the name of the module import.
As an example of what I don't want
import coke
coke.make(data)
Now an example of what I do want
import coke
make(data)
Is such possible in Python?
You want:
from coke import *
make(data)
or to import individual functions or classes:
from coke import make, make2
Let your users do what they want to do:
import coke
coke.make()
or
from coke import make
make()
or
from coke import *
make()
You can't stop them, so don't fret about it.
精彩评论