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.
For example, this is basically what I need to do in script A and B
开发者_JAVA技巧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?
You could just make a function in A.py
to pass the values into:
def DoStuff(p1, p2):
#work with dict here
Side note: Don't use strings for clearly numerical values like player health.
精彩评论