Search code examples
pythonparametersarguments

How to "ignore" arguments


I'm making a task manager in python that uses a json file as an archive and to save the informations that the user gives to the program i made a python file with different functions that manages those inputs.

And then when the infos are collected I made a function that adds those infos to the json file

import json

def setTitle():
    #collects user's input

    appendJson(task=userInput)

def setDescription():
     #collects user's input

     appendJson(description=userInput)

def appendJson (task, description):
     #generate the json item

When I run the code it gives me an error because I didn't mention the other arguments. So basically I should've wrote appendJson(task=userInput, description=bla bla) and the problem is that the code doesn't work if I wrote that.

So is there a way to omit the second argument in the function call?

If you did not understand something tell me in the comments Thanks <3


Solution

  • Fixed it,

    Assing a default value to the arguments like this:

    def appendJson(task="default value", descripiton="defaultvalue"):
    

    You can also use

    def appendJson(task="Hello World", descripiton=None):