Apr-20-2019, 04:02 AM
I am making a shortcut thing just for fun and I'm using pickle to store the shortcuts. The problem is the error I'm getting. TIA for your help
error -
error -
Error:Traceback (most recent call last):
File "C:\Users\Chadd\Desktop\Shortcuts\Url Shortcuts.py", line 63, in <module>
pickleGrab()
File "C:\Users\Chadd\Desktop\Shortcuts\Url Shortcuts.py", line 43, in pickleGrab
shortcutDict = pickle.loads(file)
TypeError: a bytes-like object is required, not '_io.BufferedReader'Url Shortcuts.py - import webbrowser
import time
import pickle
import os
from pathlib import Path
shortcutDict = {}
d = Path(__file__).parent
def addShortcut():
global shortcutDict
url = input("What is the url ")
name = input("What would you like to name this shortcut ")
shortcutDict.update({name : url})
pickleDump()
startUp()
def chooseShortcut():
global shortcutDict
print("These are your shortcuts")
print('')
for i in shortcutDict:
print(" - " + i)
name = input("Which shortcut would you like to use ")
if name in shortcutDict:
webbrowser.open(shortcutDict[name])
startUp()
else:
print("Shortcut not found. Please browse the list of shortcuts or create a new one")
startUp()
def pickleDump():
global shortcutDict
file = open(os.path.join(str(d), 'shortcutData.txt'), 'wb')
pickle.dump(shortcutDict, file)
file.close()
def pickleGrab():
global shortcutDict
file = open(os.path.join(str(d), 'shortcutData.txt'), 'rb')
print(os.path.join(str(d), 'shortcutData.txt'))
print(file)
shortcutDict = pickle.loads(file)
print(shortcutDict)
def startUp():
global shortcutDict
decide = input("Would you like to add a shortuct y/n ")
if decide == 'y':
if shortcutDict == {}:
print("You have no shortcuts - you must add one")
startUp
else:
addShortcut()
elif decide == 'n':
chooseShortcut()
else:
print("You said %s, please try again" %decide)
startUp()
pickleGrab()
startUp()
