gpt4 book ai didi

python - 我想引用另一个 python 脚本中的变量

转载 作者:太空宇宙 更新时间:2023-11-04 10:47:10 25 4
gpt4 key购买 nike

变量AAaaa.py 中。我想在我的另一个 python 文件 bbb.py

中使用这个变量

如何访问这个变量?

最佳答案

您正在寻找 modules!

aaa.py中:

AA = 'Foo'

bbb.py中:

import aaa
print aaa.AA # Or print(aaa.AA) for Python 3
# Prints Foo

或者这也行:

from aaa import AA
print AA
# Prints Foo

关于python - 我想引用另一个 python 脚本中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16480625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com