python 中 我自定义了 两个函数 但是调用的时候说报错说未定义

在同一个。py文件中定义的函数,但是在其他函数中调用自定义函数 报错说函数未定义

如何解决
NameError: global name 'add_user_to_group' is not defined

-----------------已经解决

知道了~必须声明在使用前面,更java不一样,but c same

贴出你的代码看下,缺少引用、变量/方法混用、重复定义、拼写错误都有可能。

比如你的函数在a.py中叫fun(),要想在b.py中引用:

#!/usr/bin/env python

# this is in the b.py

import a

x = a.fun()