要从一个脚本中访问另一个脚本中的整数,可以使用以下方法:
# 另一个脚本:other_script.py
my_int = 10
# 当前脚本:main.py
import other_script
print(other_script.my_int) # 输出:10
# 另一个脚本:other_script.py
def get_my_int():
return 10
# 当前脚本:main.py
import other_script
my_int = other_script.get_my_int()
print(my_int) # 输出:10
# 另一个脚本:other_script.py
def get_my_int():
return 10
# 当前脚本:main.py
import other_script
my_int = other_script.get_my_int()
print(my_int) # 输出:10
这些方法都可以使您能够从一个脚本中访问另一个脚本中的整数。选择哪种方法取决于您的具体需求和脚本的结构。