草庐IT

argument1

全部标签

python - 在一种情况下出现 "super(): no arguments"错误但不是类似情况

classWorks(type):def__new__(cls,*args,**kwargs):print([cls,args])#outputs[,()]returnsuper().__new__(cls,args)classDoesNotWork(type):def__new__(*args,**kwargs):print([args[0],args[:0]])#outputs[,()]returnsuper().__new__(args[0],args[:0])Works()#isfineDoesNotWork()#gets"RuntimeError:super():noargu

python - 如何更改 argparse 中的文本 "optional arguments"

出于某种原因,我不在我的程序中使用位置参数,而是仅接受“可选”参数,通过narg='?'或action等工具控制参数是否真正可选='store_true'。因此,帮助文本中的“可选参数”会产生误导。我可以将它简单地显示为“参数”吗?谢谢。 最佳答案 好吧,查看argparse源代码,在我看来,它就像覆盖parser._optionals的title一样简单,就像这样:parser._optionals.title="mymandatoryarguments,theyareactuallyoptionals,butI'llcheckf

Python 错误 : X() takes exactly 1 argument (8 given)

我正在尝试构建一个匿名FTP扫描器,但我在调用函数X时遇到错误,我将X定义为接收1个参数,即ip地址,如果我不使用循环,则相同的代码有效并一一发送IP。错误是:X()恰好接受1个参数(给定8个)fromftplibimportFTPimportipcalcfromthreadingimportThreaddefX(ip):try:ftp=FTP(ip)x=ftp.login()if'ogged'instr(x):print'[+]Bingo!wegotaAnonymousFTPserverIP:'+ipexcept:returndefmain():globalipforipinipca

python - psycopg2 "TypeError: not all arguments converted during string formatting"

我正在尝试将二进制数据(漩涡哈希)插入PG表,但出现错误:TypeError:notallargumentsconvertedduringstringformatting代码:cur.execute("""INSERTINTOsessions(identity_hash,posted_on)VALUES(%s,NOW())""",identity_hash)我尝试在插入之前将conn.Binary("identity_hash")添加到变量中,但得到了同样的错误。identity_hash列是一个bytea。有什么想法吗? 最佳答案

python - "OSError: [Errno 22] Invalid argument"读取一个大文件时

我正在尝试编写一个打印文件校验和的小脚本(使用来自https://gist.github.com/Zireael-N/ed36997fd1a967d78cb2的一些代码):importsysimportosimporthashlibfile='/Users/Me/Downloads/2017-11-29-raspbian-stretch.img'withopen(file,'rb')asf:contents=f.read()print('SHA256offileis%s'%hashlib.sha256(contents).hexdigest())但我收到以下错误消息:Traceback

Python 参数解析 : "unrecognized arguments"

我正在尝试通过命令行选项使用我的程序。这是我的代码:importargparsedefmain():parser=argparse.ArgumentParser()parser.add_argument("-u","--upgrade",help="fullyautomatizedupgrade")args=parser.parse_args()ifargs.upgrade:print"Startingwithupgradeprocedure"main()当我尝试从终端(pythonscript.py-u)运行我的程序时,我希望收到消息Startingwithupgradeproced

python - 类型错误 : split() takes no keyword arguments in Python 2. x

我试图将文档的一部分分成不同的部分,这些部分由&符号分隔。这是我的:name,function,range,w,h,k,frac,constraint=str.split(str="&",num=8)错误:TypeError:split()takesnokeywordarguments有人可以向我解释错误并提供替代方法让我完成这项工作吗? 最佳答案 str.split的参数分别称为sep和maxsplit:str.split(sep="&",maxsplit=8)但是你只能在Python3.x中使用这样的参数名称。在Python2.

python - 类型错误 : count() takes exactly one argument

我是Python和Django的新手,我根据教程修改了这段代码。我在加载页面时收到TypeError:count()takesexactlyoneargument(0given)。我一直在进行故障排除和谷歌搜索,但似乎无法弄清楚。我做错了什么?defreport(request):flashcard_list=[]forflashcardinFlashcard.objects.all():flashcard_dict={}flashcard_dict['list_object']=flashcard_listflashcard_dict['words_count']=flashcard

python - 操作系统错误 : [Errno 22] Invalid argument in subprocess

python3.3.3Windows7Hereisthefullstack:Traceback(mostrecentcalllast):File"Blah\MyScript.py",line578,inCalloutput=process.communicate(input=SPACE_KEY,timeout=600)File"C:\Python33\lib\subprocess.py",line928,incommunicatestdout,stderr=self._communicate(input,endtime,timeout)File"C:\Python33\lib\subp

Python argparse : default argument stored as string, 未列出

我无法从文档中找出argparse的这种行为:importargparseparser.add_argument("--host",metavar="",dest="host",nargs=1,default="localhost",help="Nameofhostfordatabase.Defaultis'localhost'.")args=parser.parse_args()print(args)这是带和不带“--host”参数的输出:>>pythondemo.pyNamespace(host='localhost')>>pythondemo.py--hosthostNamesp