我什至不知道什么是 infile >输出文件的意思。我应该如何使用它?
我不知道如何使用Python,我正在尝试在文档上使用脚本。我不知道如何告诉它这样做!
如果我只是运行脚本,这就是我收到的消息:
Use: C:\Python27\hun2html.py infile > outfile
Traceback (most recent call last):
File "C:\Python27\hun2html.py", line 75, in <module>
sys.exit(1)
SystemExit: 1
我不确定哪些信息与了解此内容的人相关,但我相信这是代码中最相关的部分:
if __name__ == '__main__':
import sys
if not sys.argv[1:]:
print "Use: %s infile > outfile" % sys.argv[0]
sys.exit(1)
contents = open(sys.argv[1]).read()
print hun2html(contents)
它应该更改在文档中格式化。如果有人能理解这个愚蠢的问题,我真的很感激一些帮助!
I don't know how to use Python, and I'm trying to use a script on a document. I have no idea how to tell it do this!
If I just run the script, this is the message I get:
Use: C:\Python27\hun2html.py infile > outfile
Traceback (most recent call last):
File "C:\Python27\hun2html.py", line 75, in <module>
sys.exit(1)
SystemExit: 1
I'm not sure what info is relevant to anyone who knows about this stuff, but this is the most relevant part of the code, I believe:
if __name__ == '__main__':
import sys
if not sys.argv[1:]:
print "Use: %s infile > outfile" % sys.argv[0]
sys.exit(1)
contents = open(sys.argv[1]).read()
print hun2html(contents)
It's supposed to change the formatting in a document. If anyone can make sense of this stupid question, I would really appreciate some help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着您应该在 infile 处写入要用于输入的文件的路径,在 outfile 处写入要存储输出的文件的路径。例如,
请注意,输入文件作为参数传递(在代码中通过 sys.argv[1] 访问),并且输出通过管道传输,这意味着 Python 将其打印到标准输出,但因为您输入了
>
字符,它将被重定向到您指定的文件。如果您省略了>; outfile
您将看到终端上显示的输出。It means that you should write the path to the file you want to use for input where infile is and the path to the file you want to store the output where outfile is. For example,
Note that the input file is being passed as a parameter (accessed in the code by
sys.argv[1]
) and the output is being piped, meaning that the Python prints it to standard output, but because you put the>
character it will be redirected to the file you indicate. If you left off the> outfile
you would see the output displayed on your terminal.您将输入文件作为第一个参数,并将标准输出重定向到要写入结果的文件。例如:
>
符号告诉它,打印到标准输出的任何内容都将写入文件,而不是控制台。还有<
会将文件读取到标准输入。You give it the input file as the first parameter and redirect the standard output to the file where you want to write the result. For example:
The
>
symbols tells it that whatever gets printed to the standard output will get written to a file, instead of the console. There is also<
which will read a file to the standard input.假设您有一个名为
input.doc
的文档。如果您运行 hun2html.py input.doc ,它将向该终端显示输出。但是,由于您希望将输出保存在另一个文件中,因此您必须将输出重定向到一个文件。这就是
> 的地方。 outfile 开始发挥作用。如果您想将输出保存在
output.html
中,您必须这样做:希望它有帮助。
Suppose you have a document named
input.doc
. If you runhun2html.py input.doc
it will display the output to that terminal.However, since you want to have the output in another file you'll have to redirect the output to a file. That's where
> outfile
comes into play. If you want to save the output inoutput.html
, you'll have to do this:Hope it helps.