python抱怨NameError:名称未定义

时间:2020-07-07 11:52:43

标签: python linux python-2.7

我们有linux服务器-rhel 7.2版本为python 2.7,版本为pip 21

这是我用来以get_number_of_cars

运行功能的python脚本。
import os
import sys
script_dir = os.path.dirname(os.path.abspath(__file__))
print script_dir
python_files_dir = os.path.join(script_dir, 'python_files')
print python_files_dir
sys.path.append(python_files_dir)
from functions import *


val = get_number_of_cars()

函数python脚本-functions.py位于/opt/cars/python_files

函数– get_number_of_carsfunctions.py内部,如下所示

def get_number_of_cars(path='/tmp/'):
.
.
.

    return number

所以当我运行脚本/tmp/car_agency.py

我们得到

python  /tmp/car_agency.py
/opt/cars
/opt/cars/python_files
Traceback (most recent call last):
  File "/tmp/car_agency.py", line 15, in <module>
    ComponentName = get_number_of_cars()
NameError: name 'get_number_of_cars' is not defined

但这很奇怪,因为我们在get_number_of_cars中定义了函数-/opt/cars/python_files/functions.py

比其他具有相同python脚本的计算机能够正常工作

所以我怀疑带有python模块或python env的东西不好

我可以在这方面寻求帮助吗?

0 个答案:

没有答案