2

outparse の使用方法を学習しようとしています。これが状況です。セットアップが正しくなったと思います。オプションを設定する方法だけがちょっと混乱しています。基本的に、ファイル名をチェックして、特定の文字列があるかどうかを確認したいだけです。

例えば:

    python script.py -f filename.txt -a hello simple

私はそれが何かを返したい...

    Reading filename.txt....
    The word, Hello, was found at: Line 10
    The word, simple, was found at: Line 15

これが私がこれまでに持っているものです。正しく設定する方法がわかりません。ばかげた質問をして申し訳ありません:P. 前もって感謝します。

これまでのコードは次のとおりです。

    from optparse import OptionParser

    def main():

        usage = "useage: %prog [options] arg1 arg2"
        parser = OptionParser(usage)

        parser.add_option_group("-a", "--all", action="store", type="string", dest="search_and", help="find ALL lines in the file for the word1 AND word2")

        (options, args) = parser.parse_args()

        if len(args) != 1:
            parser.error("not enough number of arguments")

            #Not sure how to set the options...


    if __name__ == "__main__":
        main()
4

1 に答える 1