草庐IT

argument1

全部标签

【亲测已解决】TypeError: __init__() takes 1 positional argument but 2 were given

问题描述自学pytorch进行搭建神经网络并尝试训练时,出现了Pytorch报错TypeError:init()takes1positionalargumentbut2weregiven,然后网上查了很多原因,主要如下:1、神经网络模型定义错误或没有实例化(非本人错误原因),参考链接如下http://t.csdn.cn/YuJ9m2、类初始化定义中把__init__打成了__int__(非本人错误原因),参考链接如下http://t.csdn.cn/peSOQ3、__init__少传了参数(非本人错误原因),参考链接如下http://t.csdn.cn/L0wWT发现上述都不是我产生该错误的原

python - b'从 ANSI 1252 到 UTF-8 的重新编码失败,错误为 : "Invalid argument".' geopandas python

我正在尝试将shapefile读入GeoDataFrame。通常我只是这样做并且它有效:importpandasaspdimportgeopandasasgpdfromshapely.geometryimportPointdf=gpd.read_file("wild_fires/nbac_2016_r2_20170707_1114.shp")但这次它给了我错误:b'RecodefromANSI1252toUTF-8failedwiththeerror:"Invalidargument".'完整错误:--------------------------------------------

python - 打印到 Python : redirect vs print's file argument vs write 中的文件

我有一堆print调用需要写入文件而不是stdout。(我根本不需要stdout。)我正在考虑三种方法。其中任何一个有什么优势(包括性能)吗?完全重定向,我看到了here:importsyssaveout=sys.stdoutfsock=open('out.log','w')sys.stdout=fsockprint(x)#andmanymoreprintcalls#laterifIeverneedit:#sys.stdout=saveout#fsock.close()在每个打印语句中重定向:fsock=open('out.log','w')print(x,file=fsock)#an

python - 类型错误 : argument of type 'NoneType' is not iterable

我正在用Python制作Hangman游戏。在游戏中,一个python文件有一个函数,可以从数组中选择一个随机字符串并将其存储在一个变量中。然后将该变量传递给另一个文件中的函数。该函数将用户猜测作为字符串存储在变量中,然后检查该猜测是否在单词中。但是,每当我输入一个字母并按回车键时,我都会在这个问题的标题中得到错误。正如你所知,我使用的是Python2.7。下面是接受单词的函数的代码:importrandomeasyWords=["car","dog","apple","door","drum"]mediumWords=["airplane","monkey","bananana","

python - Selenium - visibility_of_element_located : __init__() takes exactly 2 arguments (3 given)

我在使用SeleniumPython绑定(bind)的测试代码中遇到此错误:>twitter_campaigns=wait.until(EC.visibility_of_element_located(By.CSS_SELECTOR,TWITTER_CAMPAIGNS))ETypeError:__init__()takesexactly2arguments(3given)这就是我正在执行的:classTestTwitter(TestLogin,TestBuying):defsetup(self,timeout=10):self.driver=webdriver.Firefox()sel

python - 类型错误 : run() missing 1 required positional argument: 'fetches' on Session. 运行()

我是tensorflow的新手,我正在尝试关注this入门教程。但是在“ex001.py”脚本中执行这个非常简单的代码:importtensorflowastfsess=tf.Sessionhello=tf.constant('Hello,TensorFlow!')print(hello)print(sess.run(hello))我得到以下输出Tensor("Const:0",shape=(),dtype=string)Traceback(mostrecentcalllast):File"C:\Users\Giuseppe\Desktop\ex001.py",line6,inprin

Python,与 joblib : Delayed with multiple arguments 并行化

我正在使用类似于下面的东西来并行化两个矩阵上的for循环fromjoblibimportParallel,delayedimportnumpydefprocessInput(i,j):forkinrange(len(i)):i[k]=1fortinrange(len(b)):j[t]=0returni,ja=numpy.eye(3)b=numpy.eye(3)num_cores=2(a,b)=Parallel(n_jobs=num_cores)(delayed(processInput)(i,j)fori,jinzip(a,b))但我收到以下错误:要解压的值太多(预期为2个)有没有办法

python - 类型错误 : urlopen() got multiple values for keyword argument 'body' while executing tests through Selenium and Python on Kubuntu 14. 04

我正在尝试在Kubuntu14.04上用python运行selenium。我在尝试使用chromedriver或geckodriver时收到此错误消息,两者都是相同的错误。Traceback(mostrecentcalllast):File"vse.py",line15,indriver=webdriver.Chrome(chrome_options=options,executable_path=r'/root/Desktop/chromedriver')File"/usr/local/lib/python3.4/dist-packages/selenium/webdriver/ch

python - 索引错误 : tuple index out of range when parsing method arguments

我已经检查过this问题,但在那里找不到答案。这是一个演示我的用例的简单示例:deflog(*args):message=str(args[0])arguments=tuple(args[1:])#messageitselfprint(message)#argumentsforstr.format()0print(arguments)#showsthatargumentshavecorrectindexesforindex,valueinenumerate(arguments):print("{}:{}".format(index,value))#andamountofplacehol

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

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭2年前。Improvethisquestion我在Python3中进行套接字编程时遇到问题。我得到一个异常,该异常并未导致程序崩溃,但仅显示在终端中。这是我的代码:fromPyQt4importQtCore,QtGuifromimiguiimportUi_MainWindowclassimiserv(QtGui.QMainWindow):sen