Python Forum
TypeError: get_formatted_name() missing 1 required positional argument: 'last_name'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: get_formatted_name() missing 1 required positional argument: 'last_name'
#5
@hbknjr - this is not so good solution as it (i) does not gurantee the order in which arguments were supplied (ii) the number of arguments, e.g.
get_formated_name('Hooker', 'Lee', 'John')
get_formated_name('Hooker', 'Lee', 'John', Jimi', 'Hendix')
you need to put efforts when parsing args

a similar, but in my opinion better solution is to force using keyword arguments (only python3)
def full_name(*, first_name=None, middle_name=None, last_name=None):
    names = (first_name, middle_name, last_name)
    return ' '.join(name for name in names if name)

print(full_name(first_name='john', middle_name='lee', last_name='hooker'))
print(full_name(first_name='jimi', last_name='hendrix'))
print(full_name(first_name='madonna'))
print(full_name('john', 'lennon'))
Output:
john lee hooker jimi hendrix madonna Traceback (most recent call last): File "example.py", line 8, in <module> print(full_name('john', 'lennon')) TypeError: full_name() takes 0 positional arguments but 2 were given
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


Messages In This Thread
RE: TypeError: get_formatted_name() missing 1 required positional argument: 'last_name' - by buran - Mar-28-2018, 07:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: Diagram.render() takes 1 positional argument but 2 were given sachin1361 0 340 Apr-23-2024, 06:39 AM
Last Post: sachin1361
  TypeError: a bytes-like object is required ZeroX 13 5,007 Jan-07-2023, 07:02 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 2,099 Oct-17-2022, 06:29 PM
Last Post: paulo79
  TypeError: a bytes-like object is required, not 'str' - Help Please. IanJ 3 5,069 Aug-29-2022, 05:53 PM
Last Post: deanhystad
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 5,099 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  Error: _vhstack_dispatcher() takes 1 positional argument but 9 were given alexfrol86 3 6,070 May-09-2022, 12:49 PM
Last Post: deanhystad
  What is positional argument self? Frankduc 22 6,210 Mar-06-2022, 01:18 AM
Last Post: Frankduc
  TypeError: missing a required argument: 'y' gible 0 3,082 Dec-15-2021, 02:21 AM
Last Post: gible
  positional argument: 'self' mcmxl22 8 3,596 Dec-13-2021, 10:11 PM
Last Post: deanhystad
  TypeError: missing 3 required positional arguments: wardancer84 9 11,391 Aug-19-2021, 04:27 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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