Py学习  »  Python

如何将python模块创建为单个可调用函数?

jesse • 6 年前 • 1834 次点击  

我想把模块写成函数而不是类。

有没有办法使这项工作按预期进行?

greet.py
def main(x):
    print(f'Hello {x}!')

现在如何编写模块,以便 greet 执行, main 跑。

main.py
import greet

greet('Foo') # output: Hello Foo!
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/33859
 
1834 次点击  
文章 [ 2 ]  |  最新文章 6 年前