Python Forum
Missing 2 Required Positional Arguments:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Missing 2 Required Positional Arguments:
#1
Hello, I am new to python and so I am following a tutorial to learn about the basics of python. My online instructor wanted me to past this code

-----------------------------
# Snake Tutorial Python

import math
import random
import pygame
import tkinter as tk
from tkinter import messagebox


class cube(object):
    rows = 20
    w = 500

    def __init__(self, start, dirnx=1, dirny=0, color=(255, 0, 0)):
        pass

    def move(self, dirnx, dirny):
        pass

    def draw(self, surface, eyes=False):
        pass


class snake(object):
    def __init__(self, color, pos):
        pass

    def move(self):
        pass

    def reset(self, pos):
        pass

    def addCube(self):
        pass

    def draw(self, surface):
        pass


def drawGrid(w, rows, surface):
    sizeBtwn = w // rows  # Gives us the distance between the lines

    x = 0  # Keeps track of the current x
    y = 0  # Keeps track of the current y
    for l in range(rows):  # We will draw one vertical and one horizontal line each loop
        x = x + sizeBtwn
        y = y + sizeBtwn

        pygame.draw.line(surface, (255,255,255), (x,0),(x,w))
        pygame.draw.line(surface, (255,255,255), (0,y),(w,y))


def redrawWindow(surface):
    surface.fill((0,0,0))  # Fills the screen with black
    drawGrid(surface)  # Will draw our grid lines
    pygame.display.update()  # Updates the screen


def randomSnack(rows, item):
    pass


def message_box(subject, content):
    pass


def main():
    global width, rows, s
    width = 500  # Width of our screen
    height = 500  # Height of our screen
    rows = 20  # Amount of rows

    win = pygame.display.set_mode((width, height))  # Creates our screen object

    s = snake((255, 0, 0), (10, 10))  # Creates a snake object which we will code later

    clock = pygame.time.Clock()  # creating a clock object

    flag = True
    # STARTING MAIN LOOP
    while flag:
        pygame.time.delay(50)  # This will delay the game so it doesn't run too quickly
        clock.tick(10)  # Will ensure our game runs at 10 FPS
        redrawWindow(win)  # This will refresh our screen


main()
--------------------------------
and when I did I got these outputs and I'm not sure why. Any ideas?
--------------------------------
Error:
Traceback (most recent call last): File "/Users/xx/PycharmProjects/TetrisP2/MainMessAround.py", line 88, in <module> main() File "/Users/xx/PycharmProjects/TetrisP2/MainMessAround.py", line 85, in main redrawWindow(win) # This will refresh our screen File "/Users/xx/PycharmProjects/TetrisP2/MainMessAround.py", line 56, in redrawWindow drawGrid(surface) # Will draw our grid lines TypeError: drawGrid() missing 2 required positional arguments: 'rows' and 'surface'
Reply
#2
the error is pretty clear. Your drwaGrid function expects 3 arguments:
def drawGrid(w, rows, surface):
when you call it, you pass just 1:
drawGrid(surface)
because these are positional arguments, the surface variable you pass is presumed to be w argument from function definition
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,858 Oct-17-2022, 06:29 PM
Last Post: paulo79
  TypeError: missing a required argument: 'y' gible 0 2,845 Dec-15-2021, 02:21 AM
Last Post: gible
  TypeError: missing 3 required positional arguments: wardancer84 9 10,663 Aug-19-2021, 04:27 PM
Last Post: deanhystad
  TypeError: run_oracle_job() missing 1 required positional argument: 'connection_strin python_student 1 1,938 Aug-06-2021, 08:05 PM
Last Post: SheeppOSU
  TypeError: max_value() missing 2 required positional arguments: 'alpha' and 'beta' Anldra12 2 4,167 May-15-2021, 04:15 PM
Last Post: Anldra12
  TypeError: sum() missing 1 required positional argument: 'num2' Insen 3 5,388 Jan-06-2021, 04:25 PM
Last Post: Insen
  How to reuse positional arguments entered in terminal. rcmanu95 1 1,841 Jul-04-2020, 01:00 AM
Last Post: bowlofred
  Missing 1 required position argument: 'failure' while starting thread. BradLivingstone 3 4,032 Jun-19-2020, 02:31 PM
Last Post: stullis
  TypeError: forward() missing 1 required positional argument: 'x' sveto4ka 4 12,172 Jun-17-2020, 07:25 PM
Last Post: sveto4ka
  missing 1 required positional argument: 'self' yasser 7 11,296 Jun-07-2020, 06:48 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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