Python Forum
Why am I getting this TypeError?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why am I getting this TypeError?
#1
Maybe it's early morning brain...The line called out is:
self.new_queue = Queue("New", sim)
and the error says:
Error:
TypeError: Queue.__init__() takes from 1 to 2 positional arguments but 3 were given
and the declaration says:
class Queue:
    def __init__(self, name: str, sim):
deanhystad write Oct-14-2023, 03:44 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Attached Files

Thumbnail(s)
   
Reply
#2
Please post the code and errors using the bbtags. Can't tell much from images.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(Oct-14-2023, 12:28 PM)menator01 Wrote: Please post the code and errors using the bbtags. Can't tell much from images.

Can’t find how to do it. Tried but doesn’t seem to do the trick…
Reply
#4
A video of how to
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#5
This example runs with no error.
class Queue:
    def __init__(self, name: str, sim):
        pass

new_queue = Queue("New", True)
The error message says that Queue is defined like this:
class Queue:
    def __init__(self, name=""):
I think Queue is not what you think it us. Is Queue a class you wrote, or is it imported?
Reply
#6
If you imported Queue from module queue, then you can use only one argument, which is the maxsize of the queue. The modules asyncio and multiprocessing modules have also a Queue implementation, which takes also maxsize.

If Queue is your implementation in a different module, then pay attention if you overload with an import your class.

from utils import Queue
from queue import Queue

# Queue is now form queue

# different order
from queue import Queue
from utils import Queue

# Queue is now form utils
Another possible error:
class Queue:
    def __init__(self, name, simu): ...

# later in code
class Queue:
    def __init__(self, name): ...

# calling now Queue, calls the latest definition of Queue,
# which takes only one argument. (the self is given implicit and is the instance of the class)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

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