Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def add_candidate():
- #!!candidate data variables defined by user input eg. soft coded candidate data
- #name = input("What is the candidate's name?: ")
- #birthday = str(input('When was the candidate born? (format: D.M.YYYY): '))
- #height = str(input('How tall is the candidate?: '))
- #weight = str(input('How much does the candidate weigh in kilograms?: '))
- #car = str(input('Does the candidate have a car?: '))
- #languages = str(input('What (programming) language/s does the candidate know? (please separate by commas, and place languages in quotation marks""): '))
- #languages_formatted = str("{languages}")
- #if car == 'Yes' or car == 'yes':
- # car = True
- #elif car == 'No' or car == 'no':
- # car == False
- filename = 'maze.json'
- listObj = []
- # Check if file exists
- if path.isfile(filename) is False:
- raise Exception("File not found")
- # Read JSON file
- with open(filename) as fp:
- listObj = json.load(fp)
- # Verify existing list
- print(listObj)
- print(type(listObj))
- #!! JSON entry to be used with input based candidate data
- #listObj.append({
- #"name": "{name}",
- #"birthday": "{birthday}",
- #"height": height,
- #"weight": weight,
- #"car": car,
- #"languages": ["{languages_formatted}"]
- #})
- #!! hard coded candidate data
- listObj.append({
- "name": "John Doe",
- "birthday": "21.02.2005",
- "height": 180,
- "weight": 69,
- "car": False,
- "languages": ["Python", "Scratch"] #Scratch OMEGALUL
- })
- # Verify updated list
- print(listObj)
- with open(filename, 'w') as json_file:
- json.dump(listObj, json_file,
- indent=4,
- separators=(',',': '))
- print('Successfully appended to the JSON file')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement