0

我有两个脚本。脚本 A 有一堆函数,其中包含变量,需要在脚本 B 中定义。

例如,这基本上是我在脚本 A 和 B 中需要做的

一个.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

如何将参数变量传递给导入的脚本?

4

1 回答 1

0

您可以只创建一个函数A.py将值传递到:

def DoStuff(p1, p2):
  #work with dict here

旁注:不要将字符串用于明确的数值,例如玩家健康。

于 2011-10-17T19:38:05.533 回答