为什么Java仍然用于Web开发?(Why Java is still used in web development?)
为什么Java仍然用于Web开发? 我只是好奇..
Why Java is still used in web development? I'm just curious..
原文:https://stackoverflow.com/questions/1298661
最满意答案
在提供的链接中,使用可选参数分析参数 ,即参数必须以
add_argument()
提到的字符串add_argument()
。所以在你的情况下你有:
ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", help = "path to the image file") ap.add_argument("-c", "--coords", help = "comma seperated list of source points") args = vars(ap.parse_args())
注意
"--image"
和"--coords"
。 这些是可选的参数,并且必须在终端中执行代码之前提及这些字符串。所以在终端上输入:
python transform_example.py --image images/example_01.png --coords "[(73, 239), (356, 117), (475, 265), (187, 443)]"
有关参数分析及其各种方式的更多详细信息,请参阅此页面 。
In the link provided, the arguments are parsed using optional arguments, i.e. arguments must be preceded with the string mentioned in
add_argument()
.So in your case you have:
ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", help = "path to the image file") ap.add_argument("-c", "--coords", help = "comma seperated list of source points") args = vars(ap.parse_args())
Notice
"--image"
and"--coords"
. These are optional arguments and these strings must be mentioned before you execute the code in the terminal.So type this on the terminal:
python transform_example.py --image images/example_01.png --coords "[(73, 239), (356, 117), (475, 265), (187, 443)]"
See THIS PAGE for more details on argument parsing and their various ways.
相关问答
更多-
由于您没有提供太多代码,我将展示一个可行的示例: import argparse parser = argparse.ArgumentParser() parser.add_argument('-t', nargs='+', type=str) # If no argument is given to parse_args() then the argument strings of # the program are taken from sys.argv. And be sure not to pa ...
-
我认为你的问题是:对于os.listdir(dir_path)中的f:以随机顺序返回文件名。 您应该在'#确定第一张图像的宽度和高度'之前添加跟随行 def name2num(name): m = re.search('img_(\d+)\.?.*', name) return int(m.group(1),10) images.sort(key=name2num) I think your problem is : for f in os.listdir(dir_path): return ...
-
store_true是store_const的子类。 这可以用来代替: In [309]: ap = argparse.ArgumentParser() In [310]: ap.add_argument('-s',action='store_const',default=(10,10), const=(100, 100)); 然后args.s将被设置为一个元组或另一个元组: In [317]: ap.parse_args([]) Out[317]: Namespace(s=(10, 10)) ...
-
OpenCV cv2.VideoCapture(0)与网络摄像头不兼容(OpenCV cv2.VideoCapture(0) is not working well with webcam)[2022-03-09]
事实证明问题来自视频源。 网络摄像头与OpenCV不兼容虽然它可以很好地与其他一些计算机视频输入包一起使用 It turns out that the problem was from the video source. The webcam was not compatible with OpenCV Although it worked with some other computer video input package very well -
无法使用“rfind”函数从文件路径中提取动物名称(Unable to extract Animal name from the File Path using 'rfind' function)[2023-01-12]
您可以使用ntpath执行此操作 import ntpath a_path = "c:\users\intel\desktop\folder\elephant.png" >>>ntpath.basename(a_path) 'elephant.png' >>>ntpath.basename(a_path).split(".")[0] 'elephant' 或者只是使用ntpath和os >>>os.path.splitext(ntpath.basename(a_path))[0] 'elephant' ... -
此行不正确。 你不需要调用vars() 。 args = vars(ap.parse_args()) 相反,试试这个: args = ap.parse_args() 此外,参数名称会自动使用-转换为使用_ 。 试试这个: a = args.names_list[0] 这里是你的程序,更正: import argparse ap = argparse.ArgumentParser() ap.add_argument('-n', '--names-list', nargs='+', default=[]) ...
-
在提供的链接中,使用可选参数分析参数 ,即参数必须以add_argument()提到的字符串add_argument() 。 所以在你的情况下你有: ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", help = "path to the image file") ap.add_argument("-c", "--coords", help = "comma seperated list of source points") ar ...
-
在python中保存图像(Saving image in python)[2023-04-11]
方法1:保存方法 im_grey.save('greyscale.png') 使用Image_object.save()方法 方法2:imsave方法 import matplotlib.image as mpimg mpimg.imsave("greyscale.png", im_grey) Method 1: save method im_grey.save('greyscale.png') Use Image_object.save() method Method 2: imsave metho ... -
我怎样才能让argparse接受“ - ”作为选项的参数?(How can I get argparse to accept “--” as an argument to an option?)[2023-05-12]
理想情况下--foo=--应该可以工作,但是当前的解析器删除所有' - ',在其位置留下一个空字符串,因此foo=[]结果。 几年前我提出了一个补丁,应该已经解决了这个问题,但是它存在于argparse积压中。 http://bugs.python.org/issue13922,http://bugs.python.org/issue14364,http://bugs.python.org/issue9571 Python argparse with - 值表示预处理sys.argv替换一个或多个--用其他 ... -
你可能想要使用os.path.join for image in imagesToStitch: print os.path.join(args["first"], image) You'll likely want to use os.path.join for image in imagesToStitch: print os.path.join(args["first"], image)