noob问题:“TypeError”错误的args数量 [英] noob question: "TypeError" wrong number of args

查看:79
本文介绍了noob问题:“TypeError”错误的args数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


尝试寻找解决方案,但错误信息是这样的,因为我无法获得任何有意义的结果。


无论如何 - 错误消息:

-------------------------- --------------------------

TypeError:addFile()只取1个参数(给定2个)

--------------------------------------------- -------


脚本使用两个参数arg1运行和arg2:

------------------------------------ ----------------

import sys

class KeyBase:

def addFile(file):

print"用这个文件中的行初始化基数"


print"这些是args"

print" args%d'" %len(sys.argv)

print sys.argv

print sys.version_info

print sys.version

>
f = sys.argv [1]

print" f =''%s''" %f

b = KeyBase()


b.addFile(f)

---------- ------------------------------------------


输出 - 包括错误消息

(看起来像stdout和stderr有点不同步......):

------- ---------------------------------------------

这些是args

Traceback(最近一次调用最后一次):


args数量3

['' C:\\home \\< .. bla bla snip ...> \\\\\\\\'',''arg1'',''arg2'']

(2,4,2,''final'',0)

2.4.2(#67,2005年10月30日,16:11:18)[MSC v.1310 32位(英特尔)]

f =''arg1''


文件" C:\Program Files \ ActiveState Komodo

3.5 \lib \ support \dbgp \ pythonlib \dbgp \client.py",第1806行,在runMain中

self.dbg.runfile(debug_args [ 0],debug_args)

文件C:\ Program Files\ActiveState Komodo

3.5 \lib\support\dbgp\pythonlib\dbgp \client.py",第1529行,在runfile中

h_execfile(file,args,module = main,tracer = self)

文件" C:\Program Files \ActiveState Komodo

3.5 \lib \ support \ dbgp\pythonlib\dbgp \client.py",第590行,在__init__

execfile(文件,全局,本地人)

文件C: \ home \hbille\projects\bc4rom\bin\test.py",第20行,在

__main__

b.addFile(f)

TypeError:addFile()只取1个参数(给定2个)

---------------------- ------------------------------


我在ActiveState中运行它WinXP上的Komodo。


希望你的巫师可以指点我正在做什么

错误或者告诉我在我的修改内容设置。


谢谢!

问候,

Holger

解决方案

Holger写道:

尝试寻找解决方案,但错误信息非常通用,我无法获得任何有意义的结果。

无论如何 - 错误消息:
------------------------------------------------- ---
TypeError:addFile()只取1个参数(给定2个)
-------------------------- --------------------------

该脚本使用两个argsarg1运行。和arg2:
---------------------------------------- ------------
导入sys

类KeyBase:
def addFile(文件):
print"初始化基数这个文件中的行




在定义自己的类时,你必须在方法定义中拼出self

参数:


def addFile(self,file):

print"用这个文件中的行初始化基数"


见:

http:// pyfaq。 infogami.com/what-is-self



oops ,这有点令人尴尬。

但是无论如何: - )


" Holger" <是**** @ gmail.com>写道:

------------------------------------ ----------------
TypeError:addFile()只需1个参数(给定2个)
------------- ---------------------------------------

--- -------------------------------------------------
import sys

类KeyBase:
def addFile(file):
print"用这个文件中的行初始化基数"




你误解了 - 或者从未跟随过 - 教程,特别是
Python如何对象方法。请按照整个教程

,了解每个示例。你将获得
然后有一个坚实的知识基础继续。


< URL:http://docs.python.org/ tut />


-

\我们不会很棒;我们不会太神奇;我们是|

` \将会令人惊讶地惊艳! - Zaphod Beeblebrox,_The |

_o__)Hitch-Hiker's Galaxy_指南,道格拉斯亚当斯|

Ben Finney


Hi guys

Tried searching for a solution to this, but the error message is so
generic, that I could not get any meaningfull results.

Anyways - errormessage:
----------------------------------------------------
TypeError: addFile() takes exactly 1 argument (2 given)
----------------------------------------------------

The script is run with two args "arg1" and "arg2":
----------------------------------------------------
import sys

class KeyBase:
def addFile(file):
print "initialize the base with lines from this file"

print "These are the args"
print "Number of args %d" % len(sys.argv)
print sys.argv
print sys.version_info
print sys.version

f = sys.argv[1]
print "f = ''%s''" % f
b = KeyBase()

b.addFile(f)
----------------------------------------------------

The output - including error message
(looks like stdout and stderr are a bit out of sync...):
----------------------------------------------------
These are the args
Traceback (most recent call last):

Number of args 3
[''C:\\home\\<.. bla bla snip ...>\\bin\\test.py'', ''arg1'', ''arg2'']
(2, 4, 2, ''final'', 0)
2.4.2 (#67, Oct 30 2005, 16:11:18) [MSC v.1310 32 bit (Intel)]
f = ''arg1''

File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 1806, in runMain
self.dbg.runfile(debug_args[0], debug_args)
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 1529, in runfile
h_execfile(file, args, module=main, tracer=self)
File "C:\Program Files\ActiveState Komodo
3.5\lib\support\dbgp\pythonlib\dbgp\client.py", line 590, in __init__
execfile(file, globals, locals)
File "C:\home\hbille\projects\bc4rom\bin\test.py", line 20, in
__main__
b.addFile(f)
TypeError: addFile() takes exactly 1 argument (2 given)
----------------------------------------------------

I''m running this inside ActiveState Komodo on WinXP.

Hope one you wizards can give me pointers to either what I''m doing
wrong or maybe advise me what to modify in my setup.

Thank you!

Regards,
Holger

解决方案

Holger wrote:

Tried searching for a solution to this, but the error message is so
generic, that I could not get any meaningfull results.

Anyways - errormessage:
----------------------------------------------------
TypeError: addFile() takes exactly 1 argument (2 given)
----------------------------------------------------

The script is run with two args "arg1" and "arg2":
----------------------------------------------------
import sys

class KeyBase:
def addFile(file):
print "initialize the base with lines from this file"



when defining your own classes, you must spell out the "self"
argument in your method definitions:

def addFile(self, file):
print "initialize the base with lines from this file"

see:

http://pyfaq.infogami.com/what-is-self

</F>


oops, that was kinda embarrassing.
But thx anyway :-)


"Holger" <is****@gmail.com> writes:

----------------------------------------------------
TypeError: addFile() takes exactly 1 argument (2 given)
----------------------------------------------------

----------------------------------------------------
import sys

class KeyBase:
def addFile(file):
print "initialize the base with lines from this file"



You''ve misunderstood -- or never followed -- the tutorial, especially
how Python does object methods. Please follow the whole tutorial
through, understanding each example as you work through it. You''ll
then have a solid basis of knowledge to go on with.

<URL:http://docs.python.org/tut/>

--
\ "We are not gonna be great; we are not gonna be amazing; we are |
`\ gonna be *amazingly* amazing!" -- Zaphod Beeblebrox, _The |
_o__) Hitch-Hiker''s Guide To The Galaxy_, Douglas Adams |
Ben Finney


这篇关于noob问题:“TypeError”错误的args数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆