argparse

利用Python开发智能阅卷系统

吃可爱长大的小学妹 提交于 2019-12-06 16:08:02
随着现代图像处理和人工智能技术的快速发展,不少学者尝试讲CV应用到教学领域,能够代替老师去阅卷,将老师从繁杂劳累的阅卷中解放出来,从而进一步有效的推动教学质量上一个台阶。 传统的人工阅卷,工作繁琐,效率低下,进度难以控制且容易出现试卷遗漏未改、登分失误等现象。 现代的“机器阅卷”,工作便捷、效率高、易操作,只需要一个相机(手机),拍照即可获取成绩,可以导入Excel表格便于存档管理。 下面我们从代码实现的角度来解释一下我们这个简易答题卡识别系统的工作原理。 第一步,导入工具包及一系列的预处理 import numpy as np import argparse import imutils import cv2 # 设置参数 ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", default="test_01.png") args = vars(ap.parse_args()) # 正确答案 ANSWER_KEY = {0: 1, 1: 4, 2: 0, 3: 3, 4: 1} # def order_points(pts): # 一共4个坐标点 rect = np.zeros((4, 2), dtype = "float32") # 按顺序找到对应坐标0,1,2,3分别是 左上,右上,右下,左下 #

python argparse小记

好久不见. 提交于 2019-12-06 14:54:24
argparse模块是从命令行向程序传参用的,本文参考官网(https://docs.python.org/2/howto/argparse.html)1.最简单的 import argparse parser = argparse.ArgumentParser() parser.add_argument("echo") args = parser.parse_args() print(args.echo)    运行时程序名加echo的值,如: python main.py 5 2.上面这样的参数来多了运行时记不住啊,怎么办?给起个名字 import argparse parser = argparse.ArgumentParser() parser.add_argument("--echo") args = parser.parse_args() print(args.echo)   运行时就能区分啦:python 111.py --echo 5 3.好记是好记了,但是不好敲啊,这么长,怎么办?起个缩写 import argparse parser = argparse.ArgumentParser() parser.add_argument("-e", "--echo") args = parser.parse_args() print(args.echo)   这样

With argparse are subparsers inherently mutually exclusive?

孤街浪徒 提交于 2019-12-06 14:25:44
问题 I have a script with two primary functions, upgrade and provision. I'm using subparsers as a way to dictate the action being performed by the script but I want to avoid them being used together. This is a snippet of the code: import argparse def main(): parser = argparse.ArgumentParser() subparser = parser.add_subparsers(help='sub-command help') parser.add_argument('--user', '-u', help='User', default=None, required=True) parser.add_argument('--password', '-p', help='Password', default=None,

Using argparse to convert csv to xml in python

陌路散爱 提交于 2019-12-06 13:05:23
A really quick quesiton, basically my program takes an inputfile which is a csv file and then converts it into a xml file. However, the name of the xml file can either be set by the user input or if the user doesn't specify the name, then the xml file will have the same name as the csv file except with a .xml extension. I need help with the latter. So far my program works when the output file is given a name but i don't know how to set the xml file name when the user doesn't input a name. I know that if the user doesn't set a name then argparse.outputfile is none and i can write a simple if

Python multiprocessing throws error with argparse and pyinstaller

匆匆过客 提交于 2019-12-06 11:52:03
问题 In my project, I'm using argprse to pass arguments and somewhere in script I'm using multiprocessing to do rest of the calculations. Script is working fine if I call it from command prompt for ex. " python complete_script.py --arg1=xy --arg2=yz " . But after converting it to exe using Pyinstaller using command "pyinstaller --onefile complete_script.py" it throws error " error: unrecognized arguments: --multiprocessing-fork 1448" Any suggestions how could I make this work. Or any other

Parse multiple subcommands in python simultaneously or other way to group parsed arguments

一世执手 提交于 2019-12-06 11:13:00
I am converting Bash shell installer utility to Python 2.7 and need to implement complex CLI so I am able to parse tens of parameters (potentially up to ~150). These are names of Puppet class variables in addition to a dozen of generic deployment options, which where available in shell version. However after I have started to add more variables I faced are several challenges: 1. I need to group parameters into separate dictionaries so deployment options are separated from Puppet variables. If they are thrown into the same bucket, then I will have to write some logic to sort them, potentially

Mutual exclusion between argument groups

旧时模样 提交于 2019-12-06 10:01:02
I'm trying to implement the following argument dependency using the argparse module: ./prog [-h | [-v schema] file] meaning the user must pass either -h or a file, if a file is passed the user can optionally pass -v schema. That's what I have now but that doesn't seem to be working: import argparse parser = argparse.ArgumentParser() mtx = parser.add_mutually_exclusive_group() mtx.add_argument('-h', ...) grp = mtx.add_argument_group() grp.add_argument('-v', ...) grp.add_argument('file', ...) args = parser.parse_args() It looks like you can't add an arg group to a mutex group or am I missing

argparse and unittest python

送分小仙女□ 提交于 2019-12-06 07:16:36
问题 I am using argparse to handle command line arguments. Code was working fine. However as soon as I am adding unittest.main() in the main, it is not working. I am getting: I am here option -i not recognized Usage: testing.py [options] [test] [...] Options: -h, --help Show this message -v, --verbose Verbose output -q, --quiet Minimal output -f, --failfast Stop on first failure -c, --catch Catch control-C and display results -b, --buffer Buffer stdout and stderr during test runs Examples: testing

Is Python 'sys.argv' limited in the maximum number of arguments?

社会主义新天地 提交于 2019-12-06 07:05:36
问题 I have a Python script that needs to process a large number of files. To get around Linux's relatively small limit on the number of arguments that can be passed to a command, I am using find -print0 with xargs -0 . I know another option would be to use Python's glob module, but that won't help when I have a more advanced find command, looking for modification times, etc. When running my script on a large number of files, Python only accepts a subset of the arguments, a limitation I first

Options with Options with Python argparse?

时间秒杀一切 提交于 2019-12-06 06:18:47
I'm writing a script in Python, and using argparse to parse my arguments. The script is supposed to compare two different "aligners" from a pool of available aligners, and each aligner has some configuration options. I want to be able to call my script with something like: ./script.py --aligner aligner1 --param 12 --aligner aligner2 --param 30 --other_param 28 I want to get out of this some sort of structure where the first --param option "belongs" to the first --aligner option, and the second --param and the --other_param options "belong" to the second --aligner option. Is argparse capable of