开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜