- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
代码如下:https://github.com/zSucrilhos/programming/blob/master/Python/psw-generator-ASCII-1.9.5-CLI-t7.py
在 Repl.it 上:https://repl.it/@ErickCesar/PushyFabulousTask
这是一个密码生成器,我做这个是为了好玩,主要是为了学习 Python。它工作正常,正如预期的那样,我设置了以下参数:
-np, --repeat = Generate more than one psw at a time (default=1)
-pl, --length = Password length (default=25 chars)
-pt, --type = Password's type; Can be one of the following:
1 - UPPERCASE ONLY
2 - lowercase only
3 - 1234567890 only
4 - !@#$%¨&* only
5 - Mixed 12ab!@
问题是默认的“help”参数(-h、--help)。当我尝试运行该程序时,它显示一条大错误消息:
C:\Users\Pentium IV 641\Desktop\programming\programming\Python>python psw-generator-ASCII-1.9.5-CLI-t7.py -h
Traceback (most recent call last):
File "psw-generator-ASCII-1.9.5-CLI-t7.py", line 118, in <module>
arguments = parser.parse_args()
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1730, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1762, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1968, in _parse_known_args
start_index = consume_optional(start_index)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1908, in consume_optional
take_action(action, args, option_string)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1836, in take_action
action(self, namespace, argument_values, option_string)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 1020, in __call__
parser.print_help()
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 2362, in print_help
self._print_message(self.format_help(), file)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 2346, in format_help
return formatter.format_help()
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 282, in format_help
help = self._root_section.format_help()
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 213, in format_help
item_help = join([func(*args) for func, args in self.items])
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 213, in <listcomp>
item_help = join([func(*args) for func, args in self.items])
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 213, in format_help
item_help = join([func(*args) for func, args in self.items])
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 213, in <listcomp>
item_help = join([func(*args) for func, args in self.items])
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 519, in _format_action
help_text = self._expand_help(action)
File "C:\Users\Pentium IV 641\AppData\Local\Programs\Python\Python36-32\lib\argparse.py", line 606, in _expand_help
return self._get_help_string(action) % params
ValueError: unsupported format character '?' (0xa8) at index 154
尝试添加我自己的 -h
和 --help
参数,但没有帮助。错误将以同样的方式显示。
在 Linux (Arch) 和 Windows 10 中都尝试过,同样的事情。
我不知道接下来要尝试什么,因为我不太理解错误,无法自己解决它。所以我寻求帮助。
我还查看了库文件(argparse.py),看看我是否可以更好地理解正在发生的事情(没有编辑任何内容),但我不能(这里是初学者)。提前致谢。
最佳答案
问题出在字符串中的这个字符 (%
)。
4 - !@#$%¨&* only
如果您想打印 %
,请使用 %%
而不是 %
。
像这样。
4 - !@#$%%¨&* only
This could be
argparse
seems to use%
formatting inself._get_help_string(action)
%
params, otherwise%
does not have to be escaped.
这是一个类似的相关问题Python string formatting when string contains “%s” without escaping
关于Python-Argparse : Calling the help argument returns an error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54326603/
我有一个字符串,我想多次使用它来输出 configure --help .所以我尝试在 configure.ac 中做这样的事情: AC_ARG_ENABLE([foobar],
我无法使其正确匹配。它只打印“[help]”,但我希望它匹配括号内的字符。 想要: [help] help 代码: Pattern p = Pattern.compile("\\[(\
我刚刚将vim74下载并安装到我的linux机器上。我只是为用户安装在本地。当我进入vim并执行:help时,我得到了错误。 我尝试添加: let $VIM='home/myuser/vim74' l
当我打开一个 Xcode 项目时,快速帮助功能工作得很好,但是当打开一个不在打开的项目中的文件(例如 abc.swift )时,文档不会出现。 下面是一个例子: 最佳答案 安装版本Command Li
我有一个 python click CLI。当我将 --help 传递给任何命令时,它会打印一条我喜欢的帮助消息。我发现现在很多用户都在输入 mycli help foo 而不是 mycli foo
我一直在使用 less 进行前端开发,但最近几天我遇到了这个错误。 我正在使用 PhpStorm 的观察器将 less 文件编译为 css 文件。但是当我编辑 less 文件时,编译器将这一行添加到
当我在 python 解释器中键入 help('string') 时,我得到了有关字符串类的信息。在那里,upper() 被表示为一个函数。然而,我只能将其称为 "hi".upper() 而不是 up
我希望 help 选项的作用与 --help 相同。 旁注:我创建了一个程序,其命令行行为与 svn 或 hg 相同。我设法用子解析器做到了这一点。但是我想让事情保持一致。这就是为什么我希望 help
我是 Maven 的新手。你知道我做错了什么吗(见下文)? mvn -e clean:help. + Error stacktraces are turned on. [INFO] Scannin
help format-list输出格式列表的帮助。 format-list | help输出帮助(get-help)。 最佳答案 该|或“管道”运算符将一个操作的输出重定向到另一个。因此,在这种情况
尝试从脚本检索帮助会出现以下错误: Get-Help : Cannot find Help for topic ".\Process-Test.ps1". At line:1 char:9 + get
我从常规的discord.py更改为重写版本,并且我曾经有一个自定义的!help命令。 现在,每当我发布 !help 时,它都会显示此内容以及编码的帮助消息: No Category: help S
我开发跨平台桌面应用程序,最近我发现了在小部件上使用帮助文本的乐趣。然后用户在标题栏上有一个问号按钮,单击该按钮后,他可以单击窗口中的任何小部件并查看有关它的帮助文本。非常好。 因为我认为所有程序都应
Xcode 4.5.2 Mountain Lion,Mac 应用 我严格遵守文档。帮助文件夹及其子文件夹已添加到项目/Resources 文件夹并显示为蓝色。 如有必要,文件夹引用由 xcode 添加
emulator documentation说: -audio-in Use the specified audio-input backend. 它还说 -help- Print
最近在学习argparse模块,代码下方出现Argument错误 import argparse import sys class ExecuteShell(object): def crea
我正在阅读有关 Maven 的教程,应该提到我对此一无所知。我已经成功地完成了第一章和第二章,这是关于它的设置的。但是在第 3 章“Maven Pom”中我遇到了问题。在最后一段中,它说在你想要的任何
我注意到 Windows 有这个问题,但我运行的是 Ubuntu 13.10(带有 Bash),所以我不知道出了什么问题。 尝试设置我的副本集,我运行以下命令: sudo bash # Accout
很抱歉,我在 python 程序中遇到了一个尴尬的问题。首先我是这里的新手,我是一名中国学生。请原谅我糟糕的英语。我会尽力把问题表达清楚。 错误代码在这里: def __find__(
好的,我试图环顾四周并弄清楚如何做到这一点,但无法弄清楚。这就是我想要做的。 # Run script normally .\myscript.ps1 "blah" "yo" 这些应该做同样的事情 G
我是一名优秀的程序员,十分优秀!