Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用'&燃气轮机';_Python 3.x - Fatal编程技术网

Python 3.x 使用'&燃气轮机';

Python 3.x 使用'&燃气轮机';,python-3.x,Python 3.x,我的呼叫功能有问题 我试图通过使用“>”将程序的输出重定向到文本文件 这就是我尝试过的: import subprocess subprocess.call(["python3", "test.py", ">", "file.txt"]) 但是它仍然在命令提示符上显示输出,而不是在txt文件中。有两种方法可以解决这个问题 让python处理重定向: with open('file.txt', 'w') as f: subprocess.call(["python3", "tes

我的呼叫功能有问题

我试图通过使用“>”将程序的输出重定向到文本文件

这就是我尝试过的:

import subprocess

subprocess.call(["python3", "test.py", ">", "file.txt"])

但是它仍然在命令提示符上显示输出,而不是在txt文件中。有两种方法可以解决这个问题

  • 让python处理重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 使shell句柄重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 一般来说,第一种是首选的,因为它避免了外壳的变幻莫测


    最后,您应该研究
    test.py
    是否可以作为导入的模块运行,而不是通过
    子流程调用它。Python的设计便于编写脚本,因此相同的功能可以在命令行(
    python3 test.py
    )或模块(
    import test
    )中使用。

    有两种方法可以解决此问题

  • 让python处理重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 使shell句柄重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 一般来说,第一种是首选的,因为它避免了外壳的变幻莫测


    最后,您应该研究
    test.py
    是否可以作为导入的模块运行,而不是通过
    子流程调用它。Python的设计便于编写脚本,因此相同的功能可以在命令行(
    python3 test.py
    )或模块(
    import test
    )中使用。

    有两种方法可以解决此问题

  • 让python处理重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 使shell句柄重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 一般来说,第一种是首选的,因为它避免了外壳的变幻莫测


    最后,您应该研究
    test.py
    是否可以作为导入的模块运行,而不是通过
    子流程调用它。Python的设计便于编写脚本,因此相同的功能可以在命令行(
    python3 test.py
    )或模块(
    import test
    )中使用。

    有两种方法可以解决此问题

  • 让python处理重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 使shell句柄重定向:

    with open('file.txt', 'w') as f:
        subprocess.call(["python3", "test.py"], stdout=f)
    
    subprocess.call(["python3 test.py >file.txt"], shell=True)
    
  • 一般来说,第一种是首选的,因为它避免了外壳的变幻莫测


    最后,您应该研究
    test.py
    是否可以作为导入的模块运行,而不是通过
    子流程调用它。Python的设计便于编写脚本,因此在命令行(
    python3 test.py
    )或作为模块(
    import test
    )中都可以使用相同的功能。

    通过
    重定向是一种shell功能,但当您调用
    调用时,它不生成shell,而是直接执行程序,将剩余的字符串作为参数传递给它。是一个相关的问题,我记得在过去的几周里看到了更多类似的问题。通过
    重定向是一个shell功能,但是当您调用
    调用
    时,它不会生成shell,而是直接执行程序,将剩余的字符串作为参数传递给它。这个问题经常被问到。是一个相关的问题,我记得在过去的几周里看到了更多类似的问题。通过
    重定向是一个shell功能,但是当您调用
    调用
    时,它不会生成shell,而是直接执行程序,将剩余的字符串作为参数传递给它。这个问题经常被问到。是一个相关的问题,我记得在过去的几周里看到了更多类似的问题。通过
    重定向是一个shell功能,但是当您调用
    调用
    时,它不会生成shell,而是直接执行程序,将剩余的字符串作为参数传递给它。这个问题经常被问到。这是一个相关的问题,我记得在过去的几周里,我看到了更多类似的问题。