【发布时间】:2016-02-24 11:25:01
【问题描述】:
这段代码中 Python 2 和 Python 3 有什么不同吗?
if __name__ == '__main__':
argparser.add_argument("--file", required=True, help="Video file to upload")
argparser.add_argument("--title", help="Video title", default="Test Title")
argparser.add_argument("--description", help="Video description",
default="Test Description")
argparser.add_argument("--category", default="22",
help="Numeric video category. " +
"See https://developers.google.com/youtube/v3/docs/videoCategories/list")
argparser.add_argument("--keywords", help="Video keywords, comma separated",
default="")
argparser.add_argument("--privacyStatus", choices=VALID_PRIVACY_STATUSES,
default=VALID_PRIVACY_STATUSES[0], help="Video privacy status.")
args = argparser.parse_args()
运行程序时我得到:
error: the following arguments are required: --file
【问题讨论】:
-
不,在 py 2.x 和 py3k 上相同。但是错误信息已经很清楚了:
--file参数是必需的,并且您没有在命令行中指定它。但是,恕我直言,这是非常愚蠢的 CLI 设计。为什么要为 required 参数使用长选项(此外,无论如何只有一个必需参数)?只需使用位置参数。 -
愚蠢的 CLI 设计,不管是不是官方的。
-
--file的名字并不长。脚本需要知道它应该上传什么视频文件的一种或其他方式。 -
@4ae1e1 - 在本示例中使用必需的标记参数使其与本指南中的其他示例保持一致。
--file并不总是必需的。仅仅因为在这种情况下需要它而将其更改为“位置”会更加混乱。
标签: python api python-3.x youtube-api argparse