def Koben(ben, *args, **kwargs):
try:
return ben(*args, **kwargs)
except Exception as err:
print(type(err))
raise
a = Koben(nama="koben")
you have a mandatory positional argument ben
when you call the function you supply just one keyword argument that will be placed in kwargs dict
def Koben(ben, *args, **kwargs):
try:
return ben(*args, **kwargs)
except Exception as err:
print(type(err))
raise
a = Koben(nama="koben")
print(a.ben())
Error:
a = Koben(nama="koben")
TypeError: Koben() missing 1 required positional argument: 'ben'
(Apr-09-2020, 08:31 AM)buran Wrote: [ -> ]you have a mandatory positional argument ben
when you call the function you supply just one keyword argument that will be placed in kwargs dict
that's the same code. You need to supply argument
ben
. I guess that is supposed to be something callable - function, class..
def Contoh(tes, *args, **kwargs):
try:
return tes(*args, **kwargs)
except Exception as err:
print(type(err))
raise
a = Contoh(nama="Tes")
print(a.tes())
Error:
a = Contoh(nama="Tes")
TypeError: Contoh() missing 1 required positional argument: 'tes'
you have a function
Contoh
this function takes arguments. One of these arguments is mandatory -
tes
. this argument must be callable, e.g. function or class
you keep calling that function without supplying this argument.
Can you provide more context? Without it, example would be something like
def greet(name):
print(f'Hello, {name}')
def say(tes, *args, **kwargs):
print(tes)
print(args)
print(kwargs)
tes(*args, **kwargs)
say(greet, name='John')
def example(file, separator, *args):
file.write(separator.join(args))
print(file)
a = example("Helo",separator='#')
print(a)
Error:
file.write(separator.join(args))
AttributeError: 'str' object has no attribute 'write'
Please, keep the discussion in one thread, no need to start new thread every time.
In this case the first argument - file
must have write
method. You pas str
which does not have such method.
Seriously, you need to go through fundamentals
Also, note that the way you call the function - with separator as keyword argument, you virtually make
*args` useless
do i have instructions on that code
I followed the code in the python documentation
(Apr-12-2020, 07:42 PM)kobencry Wrote: [ -> ]I followed the code in the python documentation
Post a link to documentation you follow