Python Forum
help mising 1 required posisitional rgument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help mising 1 required posisitional rgument
#1
def Koben(ben, *args, **kwargs):

      try:
            return ben(*args, **kwargs)

      except Exception as err:
            print(type(err))

            raise
a = Koben(nama="koben")
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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'
Reply
#4
(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..
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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'
Reply
#6
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')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
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'
Reply
#8
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
do i have instructions on that code
I followed the code in the python documentation
Reply
#10
(Apr-12-2020, 07:42 PM)kobencry Wrote: I followed the code in the python documentation
Post a link to documentation you follow
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020