By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Constructor class problem

P: n/a
Hi,
I am a newbie and have to modify some python moduls.
I get the followin error:
TypeError: __init__() takes exactly 3 arguments (2 given)

Here the code snippet:
class gXconv:
def __init__(self, pathValue):
self.pathValue=pathValue
self.__sections = {}
self.__spalten = {}
self.labelfiles=[]
etc.....

call:
try:
gx=gXconv.gXconv(gXconfPath)
except gXconv.gXconvertError, msg:
print msg
sys.exit(1)

Hoping for hints.....
Wolfgang
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Wolfgang wrote:
Hi,
I am a newbie and have to modify some python moduls.
I get the followin error:
TypeError: __init__() takes exactly 3 arguments (2 given)

Here the code snippet:
class gXconv:
def __init__(self, pathValue):
self.pathValue=pathValue
self.__sections = {}
self.__spalten = {}
self.labelfiles=[]
etc.....

call:
try:
gx=gXconv.gXconv(gXconfPath)
except gXconv.gXconvertError, msg:
print msg
sys.exit(1)

That error can't appear in the above code - is the line in the stacktrace
amongst the shown ones? I doubt it.

The error means that you tried to call a function with less arguments than
it expected. As in __init__ the first argument is implicit on creation of
an object, the above errormessage indicates that there is an __init__
of the form

class Foo:
def __init__(self, arg1, arg2)
pass

called like this

Foo("bar")

But as the only constructor you show _has_ only one additional argument
besides self and line

gx=gXconv.gXconv(gXconfPath)

shows that you called it properly, the error must come from somewhere else.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

P: n/a
Diez B. Roggisch wrote:
Wolfgang wrote:

Hi,
I am a newbie and have to modify some python moduls.
I get the followin error:
TypeError: __init__() takes exactly 3 arguments (2 given)

Here the code snippet:
class gXconv:
def __init__(self, pathValue):
self.pathValue=pathValue
self.__sections = {}
self.__spalten = {}
self.labelfiles=[]
etc.....

call:
try:
gx=gXconv.gXconv(gXconfPath)
except gXconv.gXconvertError, msg:
print msg
sys.exit(1)


That error can't appear in the above code - is the line in the stacktrace
amongst the shown ones? I doubt it.

The error means that you tried to call a function with less arguments than
it expected. As in __init__ the first argument is implicit on creation of
an object, the above errormessage indicates that there is an __init__
of the form

class Foo:
def __init__(self, arg1, arg2)
pass

called like this

Foo("bar")

But as the only constructor you show _has_ only one additional argument
besides self and line

gx=gXconv.gXconv(gXconfPath)

shows that you called it properly, the error must come from somewhere else.


And the easiest way to track it down is to add some temporary
print "I am in <some function or method name>."
debug messages through your code.
By looking at which messages pop up, you can trace what happens just
before your program bombs.

Joal
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.