开发者

I don't even know what infile > outfile means. How am I supposed to use it?

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 jus开发者_运维知识库t 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!


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,

C:\Python27\hun2html.py C:\input.txt > C:\output.txt

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:

C:\Python27\hun2html.py myfile.hun >myfile.html

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.


Suppose you have a document named input.doc. If you run hun2html.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 in output.html, you'll have to do this:

hun2html.py input.doc > output.html

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜