日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python 参数解析器_Python参数解析器,在h之前引发异常

發(fā)布時間:2025/3/21 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 参数解析器_Python参数解析器,在h之前引发异常 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我不知道為什么會這樣。我的理解是用戶至少有機會在執(zhí)行默認(rèn)操作之前使用-h。import os, sys, argparse

class argument_parser():

# call on all our file type parsers in the sequence_anlysis_method

def __init__(self):

self.db_directory = os.path.dirname(os.path.abspath(sys.argv[0]))

"""A customized argument parser that does a LOT of error checking"""

self.parser = argparse.ArgumentParser(

prog="igblast")

general = self.parser.add_argument_group(

title="\nGeneral Settings")

general.add_argument(

"-x", '--executable',

default="/usr/bin/igblastn",

type=self._check_if_executable_exists,

help="The location of the executable, default is /usr/bin/igblastn")

self.args = self.parser.parse_args()

def _check_if_executable_exists(self,x_path):

if not os.path.exists(x_path):

msg = "path to executable {0} does not exist, use -h for help\n".format(x_path)

raise argparse.ArgumentTypeError(msg)

if not os.access(x_path, os.R_OK):

msg1 = "executable {0} does have not permission to run\n".format(x_path)

raise argparse.ArgumentTypeError(msg1)

else:

return x_path

if __name__ == '__main__':

argument_class = argument_parser()

現(xiàn)在,如果/usr/bin/igblastn在那里,那么就可以了,但是如果不是的話,只要調(diào)用這個程序就會在self\u check_中引發(fā)異常,如果有可執(zhí)行文件。

^{pr2}$

根據(jù)我的理解,用戶總是有機會運行--help或-h,或者在采取任何導(dǎo)致此參數(shù)錯誤的操作之前。我對arg解析器的理解不清楚嗎?

總結(jié)

以上是生活随笔為你收集整理的python 参数解析器_Python参数解析器,在h之前引发异常的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。