我正在编写一个程序:prog1,它正在导入另一个模块来定义一个变量。
它是这样工作的:
import modulename1
var1 = attribute1 #situated in modulename1
import modulename2
var2 = attribute2()
function2(var1): # Imagine this being a api call with var1 part of url
#api call
return response.text
function3(function2(var1)+ var2)
模块1:
attribute1 = input('user value')
模块2:
def attribute2():
from prog 1 import var 1
atr2 = function(var1) + 'word' #Imagine the function as an api call at
return atr2 #this space
modulename1接受用户input
定义变量attribute1。
现在,另一个模块:modulename2需要使用modulename1中的值导入var1
但是,它不能直接从modulename1导入,因为prog 1是用户启动的程序,再次导入modulename1可能会导致不同的用户^{
modulename2依次处理var1并定义attribute2
var2然后再次用于prog1。有办法吗
条件
两个模块都必须完全导入
出于显而易见的原因,modulename2不应导入modulename1
目前没有回答
相关问题 更多 >
编程相关推荐