无法在另一个python文件中获取一个python文件的全局变量值

无法在另一个python文件中获取一个python文件的全局变量值,python,pycharm,global-variables,Python,Pycharm,Global Variables,文件2.py name1 = [] class VideoCamera(object): def process_and_encode(images): # initialize the list of known encodings and known names known_encodings = [] known_names = [] name1 = [] print("[LOG] Encoding faces ...")

文件2.py

name1 = []
class VideoCamera(object):

   def process_and_encode(images):
   # initialize the list of known encodings and known names
   known_encodings = []
   known_names = []
   name1 = []
   print("[LOG] Encoding faces ...")

    for image_path in tqdm(images):
        #  For Loading  image
        image = cv2.imread(image_path)
        # Converting it from BGR to RGB
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        # detect face in the image and get its location (square boxes coordinates)
        boxes = face_recognition.face_locations(image, model='hog')

        # Encode the face into a 128-d embeddings vector
        encoding = face_recognition.face_encodings(image, boxes)

        # the person's name is the name of the folder where the image comes from
        name = image_path.split(os.path.sep)[-2]

        if len(encoding) > 0:
            known_encodings.append(encoding[0])
            known_names.append(name)
            name1.append(name)
            print (name1)

    return {"encodings": known_encodings, "names": known_names,"name1": name1}
main.py

from flask import Flask, render_template,request,session,Response
from flask_mysqldb import MySQL
from camera import *
from twilio.rest import Client
import time
import random
@app.route('/otp',methods=['POST'])
def otp():
     print("Name")
     print(name1)
if name1 == "Tejaswi":
    return render_template('sucess.html')
else:
    return render_template('failed.html')
在main.py[]中-正在打印空列表,而不是打印名称1的更新值。如何在此main.py.中打印gloabla变量值。。 现在我已经这样编辑了,但输出仍然是空列表


请帮帮我

好的,我编辑了一些东西。这里是file2.py

class VideoCamera(object):
   global name1
   def process_and_encode(images):
   # initialize the list of known encodings and known names
        known_encodings = []
        known_names = []
        name1 = []
        print("[LOG] Encoding faces ...")

        for image_path in tqdm(images):
            #  For Loading  image
            image = cv2.imread(image_path)
            # Converting it from BGR to RGB
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

            # detect face in the image and get its location (square boxes coordinates)
            boxes = face_recognition.face_locations(image, model='hog')

            # Encode the face into a 128-d embeddings vector
            encoding = face_recognition.face_encodings(image, boxes)

            # the person's name is the name of the folder where the image comes from
            name = image_path.split(os.path.sep)[-2]

            if len(encoding) > 0:
                known_encodings.append(encoding[0])
                known_names.append(name)
                name1.append(name)
                print (name1)

                return {"encodings": known_encodings, "names": known_names,"name1": name1}
这是main.py

from file2 import VideoCamera

@app.route('/otp',methods=['POST'])
def otp():
     print("Name")
     print(name1)
     if process_and_encode().name1 == "Tejaswi":
        return render_template('sucess.html')
     else:
        return render_template('failed.html')

导入值了吗?这不可能是
main.py
的全部代码。请向我们展示所有code.main.py从不定义
name1
,因此我不知道它如何运行。它将变量name1实例化为空列表。将值添加到列表时,应将其追加。问题是,我无法从这里做更多的事情,因为我在main.py的第3行遇到了一个错误,原因很明显。你也面临同样的问题,因为你需要一个指向OTP文件的链接。我没有,但你应该有,因为这是你的代码。链接后,它显示failed.html仅作为其获取空列表