简体   繁体   English

从PowerShell终端添加到Python脚本吗?

[英]Add to Python Script from PowerShell Terminal?

I'm learning Python from "Learn Python the Hard Way" by Zed A. Shaw, and can't figure out: 我正在从Zed A. Shaw的“学习Python的艰难方法”中学习Python,但无法弄清楚:

  1. I'm working in Powershell. 我在Powershell中工作。 How do I add a line of text to my python script (ex1.py) from the PowerShell terminal? 如何从PowerShell终端向我的python脚本(ex1.py)添加一行文本? I've tried (starting in PowerShell): Add-Content ex1.py "print "Hello"" and other variations, but I get the message: 我已经尝试过(从PowerShell中开始): Add-Content ex1.py "print "Hello""和其他变体,但是得到消息:

    Add-Content : A positional parameter cannot be found that accepts argument 'Hello'. Add-Content:找不到接受参数“ Hello”的位置参数。

  2. How do I run just one of the seven lines of text ex1.py currently has? 我如何只运行当前文本ex1.py的七行之一? Without doing some extra bash script? 不做一些额外的bash脚本? Again, I'm working from the Windows PowerShell terminal, so I don't think bash applies there. 同样,我正在Windows PowerShell终端上工作,所以我认为bash不适用于该终端。
  1. Use Add-Content ex1.py 'print "Hello"' 使用Add-Content ex1.py 'print "Hello"'
  2. Use python.exe -c "<cmd>" to execute a single python command. 使用python.exe -c "<cmd>"执行单个python命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM