代码之家  ›  专栏  ›  技术社区  ›  one-hand-octopus

如何在运行脚本后在终端显示变量?[复制]

  •  0
  • one-hand-octopus  · 技术社区  · 6 年前

    How do I run a Python program? 我可以在命令提示符中使用

    C:\python>python first.py
    

    ,运行 first.py

    但是,有没有可能,在我进入交互式python提示符之后,通过运行

    C:\python>python 
    

    看看 >>> python指示,运行 第一.py ,运行结束后 第一.py ?

    例如,如果 第一.py

    (x,y) = [3,5]
    

    ,是否可能在运行后 回到交互式python提示符, x y

    Running windows shell commands with python

    >>>os.system('python first.py')
    

    第一.py ,但是 是的 运行后内部定义丢失。

    0 回复  |  直到 8 年前
        1
  •  10
  •   Sawant    8 年前

    对于Python 2.x,请尝试以下操作:

    >>> execfile('first.py')
    

    对于Python 3.x,请尝试以下操作:

    >>> exec(open("./first.py").read())
    

        2
  •  8
  •   Christian König    8 年前

    使用

    C:\python>python -i first.py