Type error: dump() missing 1 required positional argument: fp - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Type error: dump() missing 1 required positional argument: fp (/thread-19707.html) |
Type error: dump() missing 1 required positional argument: fp - jaycuff13 - Jul-11-2019 Hi, I am trying to create a json file that stores my users email for subscription purposes. I get an error that says, 'Type error: dump() missing 1 required positional'. Here is my code: print('Welcome to the Urban ') import json import username import favartist def userfav(): userfav = input('Please select your favorite artist: \n ') a = 'Yes' or 'yes' ab = 'No' or 'no' if userfav == 'Drake': subs = input('Would you like to subscribe to notifications for Drake?:') if subs == a: print('Thank you for subscribing') elif subs == ab: print('You ca subscribe later') else: print('Selection is invalid') elif userfav == 'J.Cole': subs = input('Would you like to subscribe to notifications for J.Cole?:') if subs == a: print('Thank you for subscribing') elif subs == ab: print('You ca subscribe later') else: print('Selection is invalid') elif userfav == 'Anderson Paak': subs = input('Would you like to subscribe to notifications for Drake?:') if subs == a: print('Thank you for subscribing') ussubem() elif subs == ab: print('You ca subscribe later') else: print('Selection is invalid') userfav() def ussubem(): userfav = True a = True sub_e = input('Please enter your subscription email: \n ') em = sub_e return print('Thank you, will now receive regular emails about The Urban Macchiato to,' + sub_e) ussubem() with open('usersub.json', 'w+') as json_file: json.dump(ussubem) RE: Type error: dump() missing 1 required positional argument: fp - snippsat - Jul-11-2019 To make it work,also for now remove stuff that don't make sense. import json def ussubem(): sub_e = input('Please enter your subscription email: \n ') return f'Thank you, will now receive regular emails about The Urban Macchiato to {sub_e}' email = ussubem() with open('usersub.json', 'w') as json_file: json.dump(email, json_file)When you do userfav = True it's overwrite function userfav() then all code is gone and it's only True.To check a condition in function then something like this: if 'email stuff' in userfav(): # Write json else: # Not okay,try again RE: Type error: dump() missing 1 required positional argument: fp - jaycuff13 - Jul-13-2019 Okay, I have gotten rid of some of the unnecessary code, but I am still receiving error messages. Here is my code: print('Welcome to the Urban ') import json import username import favartist def userfav(): userfav = input('Please select your favorite artist: \n ') a = 'Yes' or 'yes' ab = 'No' or 'no' if userfav == 'Drake': subs = input('Would you like to subscribe to notifications for Drake?:') if subs == a: print('Thank you for subscribing') elif subs == ab: print('You ca subscribe later') else: print('Selection is invalid') elif userfav == 'J.Cole': subs = input('Would you like to subscribe to notifications for J.Cole?:') if subs == a: print('Thank you for subscribing') elif subs == ab: print('You ca subscribe later') else: print('Selection is invalid') elif userfav == 'Anderson Paak': subs = input('Would you like to subscribe to notifications for Drake?:') if subs == a: print('Thank you for subscribing') ussubem() elif subs == ab: print('You can subscribe later') def ussubem(): a = True sub_e = input('Please enter your subscription email: \n ') return print('Thank you, will now receive regular emails about The Urban Macchiato to,' + sub_e) userfav() ussubem() def writesub(ussubem): with open('usersub.json', 'w+') as f: json.dump(sub_em, f) writesub(ussubem) |