I get the following error when I'm reading my .pkl files on spyder (python 3.6.5):
IN: with open(file, "rb") as f:
data = pickle.load(f)
Traceback (most recent call last):
File "<ipython-input-5-d9796b902b88>", line 2, in <module>
data = pickle.load(f)
AttributeError: Can't get attribute 'Signal' on <module '__main__' from 'C:\\Python36\\lib\\site-packages\\spyder\\utils\\ipython\\start_kernel.py'>
The context:
My program is made of one file: program.py
In the program, a class Signal
is defined as well as many functions. A simplified overview of the program is provided below:
import numpy as np
import _pickle as pickle
import os
# The unique class
class Signal:
def __init__(self, fq, t0, tf):
self.fq = fq
self.t0 = t0
self.tf = tf
self.timeline = np.round(np.arange(t0, tf, 1/fq*1000), 3)
# The functions
def write_file(data, folder_path, file_name):
with open(join(folder_path, file_name), "wb") as output:
pickle.dump(data, output, -1)
def read_file(folder_path, file_name):
with open(join(folder_path, file_name), "rb") as input:
data= pickle.load(input)
return data
def compute_data(# parameters):
# do stuff
The function compute_data
will return a list of tuples of the form:
data = [((Signal_1_1, Signal_1_2, ...), val 1), ((Signal_2_1, Signal_2_2, ...), val 2)...]
With, of course, the Signal_i_k being an object Signal
. This list will be saved in .pkl format. Moreover, I'm doing a lot of iteration with different parameters for the compute_data
functions. Many iterations will use past computed data as a starting point, and thus will read the corresponding and needed .pkl files.
Finally, I'm using several computers at the same time, each of them saving the computed data on the local network. Thus each computer can access the data generated by the others and use it as a starting point.
Back to the error:
My main issue is that I never have this error when I start my programs by double-clicking the file or by the windows cmd or PowerShell. The program never crashes throwing this error and runs without apparent issues.
However, I can not read a .pkl file in spyder. Every time I try, the error is thrown.
Any idea why I got this weird behavior?
Thanks!