Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 2

missing 1 required positional argument

I've spent the last few hours trying to work out what's wrong with this. I'd be grateful for some help.


import json

def saveData(dataList):
    dataList = open('data.txt', 'w')
    json.dump(data.txt, dataList, indent=4)
   dataList.close()

try:
    trell=open('data.txt', 'r')
    data=json.load(trell)
    trell.close()
except:
    data=[]


vitamin_c=input('Enter milligrams of vitamin c per 100 grams ')
data.append({'vitamin_c':vitamin_c})
saveData()

 

1 Reply
Commander Lvl 2
Message 2 of 2

Re: missing 1 required positional argument

For future reference, please identify:

* the language and what version

* where the error is

 

In the last line you failed to pass a parameter to saveData. Either drop the parameter definition from the method, or pass (presumably) "data" as the parameter.

 

And if you do the latter, your next problem will be that "saveData" as written doesn't save the datalist, it loads it.

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!