Home  >  Q&A  >  body text

python 获取另一个.py中变量的值

如:在a.py文件有一个变量a = bool(),b.py去运行a.py,然后我希望能获取a.py运行后a的值,该如何去获取?

PHP中文网PHP中文网2741 days ago391

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-18 09:27:12

    Yes, you must declare it before using itglobal a

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:27:12

    Oops, the file name and variable name are duplicated.
    In b.py, import a
    to get the global variables in the a.py file

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:27:12

    a.py

    a = 1
    b = "2"
    def f():
        return "function"

    b.py

    import a
    a = a.a
    from a import b,f
    print(b)
    f()

    reply
    0
  • Cancelreply