首页 > 解决方案 > 如何将一个模块的变量添加到python中的另一个maodule

问题描述

我想将一个变量从一个模块添加到另一个模块,

同时我对声明变量有疑问。**

这是我的主要节目

import check
print("enter your name")
name=input()
if check.users:
 print("nice to see yo again")
else :
 print("nice to meet you")

这是我的另一个文件 check.py

import new
users = name=="venkatesh" or name=="rishi" or name=="arjun"

但编译器显示错误消息:

CHECK MODULE HAS NO ATTRIBUTE OF USERS

标签: pythonpython-3.xdebugging

解决方案


我想你需要这样的东西

new.py文件。

import check

user = check.user
print("enter your name")
name=input()
if check.users:
    print("nice to see yo again")
else :
    print("nice to meet you")

check.py文件

user = "Enter name of the User"
# Your check condition

推荐阅读