python - 您如何访问由其他模块用户输入定义的变量?
问题描述
我正在编写一个程序: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是由 User 启动的程序,再次导入modulename1可能会导致不同的 user 。Turn 中的modulename2处理var1并定义attribute2。然后var2再次在prog1中使用。有没有办法做到这一点?input
条件
两个模块都必须完全导入。
出于显而易见的原因 modulename2 不应该导入 modulename1
解决方案
推荐阅读
- java - 如何在使用spring集成从sftp移动到本地目录时将不同的文件保存到不同的位置
- android - Ionic 4 Deeplinking - 如果未安装应用程序,则启动网站
- sql - 如何使用 SQL Oracle 将字符串日期时间转换为字符串?
- django - 如何在 Django 视图类中设置缓存控制标头(无缓存)
- python - 熊猫数据框上的高效矢量化替换
- azure-iot-central - 在 azure IoT Central 中哪里可以找到设备的模块名称
- export - 如何出口所有产品?
- python - 添加一天到日期列 - dateadd 或 timedelta
- php - 在方法内部调用setter方法
- google-fit-api - Google Fit REST API 移动分钟数