[英]How do you pass an argument variable while to an imported script?
I have two scripts. 我有两个脚本。 Script A has a bunch of functions with variables in them, that need to be defined in Script B.
脚本A有很多函数,其中包含变量,需要在脚本B中定义。
For example, this is basically what I need to do in script A and B 例如,这基本上是我在脚本A和B中需要做的
A.py: A.py:
health = {p1:"100", p2:"100"}
The rest of the script requires that dictionary to be defined. 脚本的其余部分要求定义字典。
B.py: 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? 如何将参数变量传递给导入的脚本?
You could just make a function in A.py
to pass the values into: 您只需在
A.py
创建一个函数即可将值传递到:
def DoStuff(p1, p2):
#work with dict here
Side note: Don't use strings for clearly numerical values like player health. 旁注:请勿将字符串用于明确的数字值,例如玩家健康状况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.