Why do I get Pickle - EOFError: Ran out of input reading an empty file?
I would check that the file is not empty first:
import os
scores = {} # scores is an empty dict already
if os.path.getsize(target) > 0:
with open(target, "rb") as f:
unpickler = pickle.Unpickler(f)
# if file is not empty scores will be equal
# to the value unpickled
scores = unpickler.load()
Also open(target, 'a').close()
is doing nothing in your code and you don't need to use ;
.
Dealing with EOFError: Ran out of input error from file that is constantly updated
To answer your question about 20 tries, you can use a loop. Make sure to catch the specific exception, in case a different error is thrown.
for i in range(20):
try:
df = pd.read_pickle('data')
except EOFError:
time.sleep(0.5)
EOFError: Ran out of input and file im trying to pickle is not empty
Working example:
import pickle
password_input = '123123123'
pickle_out = open("steam_password.pickle","wb")
pickle.dump(password_input, pickle_out)
pickle_out.close()
pickle_inn = open('steam_password.pickle','rb')
password = pickle.load(pickle_inn)
pickle_out.close just makes reference to function, don't calls it
And it's definetly bad idea to store password in pickle file. You can store it as md5 hash:
import hashlib
password = '123123123'
hashlib.md5(password.encode('utf8')).hexdigest()
Related Topics
How to Draw Axis in the Middle of the Figure
How to Upload a File to Google Cloud Storage on Python 3
Keep Persistent Variables in Memory Between Runs of Python Script
Iso to Datetime Object: 'Z' Is a Bad Directive
How to Left Align a Fixed Width String
Go to a Specific Line in Python
Using Self.Xxxx as a Default Parameter - Python
Pandas Unique Values Multiple Columns
Use Aws Glue Python with Numpy and Pandas Python Packages
Printing Without Newline (Print 'A',) Prints a Space, How to Remove
Django Model "Doesn't Declare an Explicit App_Label"
Matplotlib: How to Draw a Rectangle on Image
How to "Zip Sort" Parallel Numpy Arrays
How to Call Python Code from C Code
Preprocessing in Scikit Learn - Single Sample - Depreciation Warning
Case Insensitive Flask-Sqlalchemy Query
How to Create an Object for a Django Model with a Many to Many Field
Suppress Insecurerequestwarning: Unverified Https Request Is Being Made in Python2.6