如何将参数变量 while 传递给导入的脚本?
我有两个脚本。脚本 A 有一堆带有变量的函数,需要在脚本 B 中定义。
例如,这基本上就是我在脚本 A 和 B
A.py 中需要做的事情:
health = {p1:"100", p2:"100"}
脚本的其余部分需要该字典被定义。
B.py:
p1 = raw_input()
p2 = raw_input()
from A.py import *
#Here, I get the error that p1 and p2 aren't defined in A.py
#I need to pass p1 and p2 (in B.py) to the health dict in A.py
如何将参数变量传递给导入的脚本?
I have two scripts. Script A has a bunch of functions with variables in them, that need to be defined in Script B.
For example, this is basically what I need to do in script A and B
A.py:
health = {p1:"100", p2:"100"}
The rest of the script requires that dictionary to be defined.
B.py:
p1 = raw_input()
p2 = raw_input()
from A.py import *
#Here, I get the error that p1 and p2 aren't defined in A.py
#I need to pass p1 and p2 (in B.py) to the health dict in A.py
How do I pass an argument variable to an imported script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
A.py
中创建一个函数来将值传递到:旁注:不要使用字符串来表示明确的数值,例如玩家生命值。
You could just make a function in
A.py
to pass the values into:Side note: Don't use strings for clearly numerical values like player health.