I'm trying to figure out the error that occurred using Python. I'm trying to use the module detektspikes.py freely distributed by klustakwik team.
I'm having trouble with errors that occurred when run.
Error log:
Exiting directory C:\Users\user\Downloads\klusta-team-spikedetekt-82bcf06\klusta
-team-spikedetekt-82bcf06\scripts_1
Traceback (most recent call last):
File "C:\Users\user\Downloads\klusta-team-spikedetekt-82bcf06\klusta-team-spik
edetekt-82bcf06\scripts\detektspikes.py", line 82, in <module>
spike_detection_job(raw_data_files, probe_file, output_dir, output_name)
File "C:\Python27\lib\site-packages\spikedetekt\core.py", line 86, in
spike_de
tection_job
probe, max_spikes)
File "C:\Python27\lib\site-packages\spikedetekt\core.py", line 115, in
spike_d
etection_from_raw_data
h5s[n] = tables.openFile(filename, 'w')
AttributeError: 'module' object has no attribute 'openFile'
I guess the problem is on the core.py
Core.py :
Filter, detect, extract from raw data.
"""
### Detect spikes. For each detected spike, send it to spike writer, which
### writes it to a spk file. List of times is small (memorywise) so we just
### store the list and write it later.
np.savetxt("dat_channels.txt", Channels_dat, fmt="%i")
# Create HDF5 files
h5s = {}
h5s_filenames = {}
for n in ['main', 'waves']:
filename = basename+'.'+n+'.h5'
h5s[n] = tables.openFile(filename, 'w')
h5s_filenames[n] = filename
for n in ['raw', 'high', 'low']:
if Parameters['RECORD_'+n.upper()]:
filename = basename+'.'+n+'.h5'
h5s[n] = tables.openFile(filename, 'w')
h5s_filenames[n] = filename
main_h5 = h5s['main']
# Shanks groups
shanks_group = {}
shank_group = {}
shank_table = {}
for k in ['main', 'waves']:
h5 = h5s[k]
shanks_group[k] = h5.createGroup('/', 'shanks')
for i in probe.shanks_set:
I would pleased to be kindly helped!
The problem is that that code is for a very old version of Python and trying to access a no longer existing method of tables. See here: http://www.pytables.org/MIGRATING_TO_3.x.html
If you want to run the script you'd have to run it in an old version of Python like 2.3, or update the lines that use openFile to use open_file instead. Though there may be other incompatibilities that I'm not aware of.
Related
I was making my simple filereader using python and cpython. But, I realized that it displayed an error that is TypeError: 'list' object has to attribute to find. Is there any way to find a specific character inside a list and return it? Thanks :D
Main python module
import io;
class AdvancedReader(object):
def __init__(self, file, mode=None, buffering=None, encoding=None, *args):
data_file = io.open(file, mode=mode, buffering=buffering, encoding=encoding)
striped_list = [lines.strip() for lines in (data_file.readlines())]
if any(map('['.startswith and ']'.endswith, striped_list)):
_starter = ([for item in striped_list.startswith('[')])
# stater = striped_list.filter('[', ‘]’) #Removing brackets
Simple using for class
AdvancedReader('settings.def', mode='r', buffering=-1, encoding='utf-8')
This is the atributte error that displayed inside my class...
Traceback (most recent call last):
File "main. py"
, line 13, in «module>
AdvancedReader("settinas.def".mode='r', buffering=-1. encoding='utf-g)
File "main.py", line 9, in
init
print(striped list. find(r))
AttributeError: list' object has no attribute 'find'
This is the settings.def file, its practically a new type of storage/file systax for python only.
[SYSTEM] // Begining acronym
start: os.system('echo hello world')
[/SYSTEM] // Ending acronym
I am facing this error when running the below code
from io import StringIO
class Runner(object):
#staticmethod
def runner(file_object):
data = file_object.readlines()
bdy = data[2:]
for line in bdy:
yield line
Error Log:
bdy = data[2:]
TypeError: 'StreamReader' object is not subscriptable
The error seems to be in bdy where it is not able to slice the data list that is obtained from file_object.readlines
Need to Fix this.
I guess you are trying to istanciate the class object in another part of the code and in that part you are calling the method runner but before make sure you opened the file correctly in read mode.
file = open("*your filename*", "r")
Finally you can call the method
my_runner = Runner()
my_runner.runner(file)
also it's good practice to close the file too
file.close()
If the problem persists check the length of the file, its existance in the folder and its path.
I'm taking a look at some CBOW Python implementations.
The owner of the code used a function called "line_processing" from text_process lib.
When I tried to run, I got that error:
ImportError: cannot import name 'line_processing' from 'text_process'
So I took a look at the lib implementation. There is no function called "line_processing".
That guy used this function to read each line from a .txt file, and write them in a variable, creating a "big string":
text = 'file.txt'
print(text)
text = ''
count = 0
for i in open(text_file, 'r', encoding='utf-8'):
text+=line_processing(i)+'\n'
count += 1
if count % 10000 == 0: break
Is there anyone who knows something about "line_processing" function, or about a function/lib I can use instead?
Thank you!
Ps.:
$ python CBOW.py
Building prefix dict from the default dictionary ...
Dumping model to file cache C:\"path_to"\AppData\Local\Temp\jieba.cache
Loading model cost 0.723 seconds.
Prefix dict has been built successfully.
Traceback (most recent call last):
File "CBOW.py", line 1, in <module>
from text_process import line_processing
ImportError: cannot import name 'line_processing' from 'text_process' (C:\"path_to"\miniconda3\lib\site\...\text_process)
I recently made a program using an external document with pickle. But when it tries to load the file with pickle, I got this error (the file is already existing but it also fails when the file in't existing):
python3.6 check-graph_amazon.py
a
b
g
URL to follow www.amazon.com
Product to follow Pool_table
h
i
[' www.amazon.com', ' Pool_table', []]
p
Traceback (most recent call last):
File "check-graph_amazon.py", line 17, in <module>
tab_simple = pickle.load(doc_simple)
io.UnsupportedOperation: read
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "check-graph_amazon.py", line 42, in <module>
pickle.dump(tab_simple, 'simple_data.dat')
TypeError: file must have a 'write' attribute
Here is the code :
import pickle5 as pickle
#import os
try:
print("a")
with open('simple_data.dat', 'rb') as doc_simple:
print("b")
tab_simple = pickle.load(doc_simple)
print("c")
print(tab_simple)
print("d")
URL = tab_simple[0]
produit_nom = tab_simple[1]
tous_jours = tab_simple[2]
print("f")
except :
print("g")
URL = str(input("URL to follow"))
produit_nom = str(input("Product to follow"))
with open('simple_data.dat', 'wb+') as doc_simple:
print("h")
#os.system('chmod +x simple_data.dat')
tab_simple = []
tab_simple.append(URL)
tab_simple.append(produit_nom)
tab_simple.append([])
print(tab_simple)
print("c'est le 2")
print("p")
pickle.dump(tab_simple, 'simple_data.dat')
print("q")
The prints are here to show which lines are executed. The os.system is here to allow writing on the file but the error is persisting.
I don't understand why it's said that the document doesn't have a write attribute because I opened it in writing mode. And I neither understand the first error where it can't load the file.
If it can help you the goal of this script is to initialise the program, with a try. It tries to open the document in reading mode in the try part and then set variables. If the document doesn't exist (because the program is lauched for the first time) it goes in the except part and create the document, before writing informations on it.
I hope you will have any clue, including changing the architecture of the code if you have a better way to make an initialisation for the 1st time the program is launched.
Thanks you in advance and sorry if the code isn't well formated, I'm a beginner with this website.
Quote from the docs for pickle.dump:
pickle.dumps(obj, protocol=None, *, fix_imports=True)
Write a pickled representation of obj to the open file object file. ...
...
The file argument must have a write() method that accepts a single bytes argument. It can thus be an on-disk file opened for binary writing, an io.BytesIO instance, or any other custom object that meets this interface.
So, you should pass to this function a file object, not a file name, like this:
with open("simple_data.dat", "wb"): as File:
pickle.dump(tab_simple, File)
Yeah, in your case the file has already been opened, so you should write to doc_simple.
This is the code snippet causing the problem:
if str(sys.argv[2]) + '.pickle' in os.listdir(os.curdir): #os.path.isfile(str(sys.argv[2]) + '.pickle'):
path = sys.argv[2] + '.pickle'
#print path
instance = cPickle.load(open(str(path)))
This is the traceback:
Traceback (most recent call last):
File "parent_cls.py", line 92, in <module>
instance = cPickle.load(open(str(path)))
EOFError
If this keeps happening because of file.close() is not performed or some other ridiculous mistake, please let me know if there is a way to access the pickle file using subprocess. Thanks.
UPDATE: Another thing I notice. The filename.pickle to check if its there or not using the if condition actually is creating a filename.pickle although it wasn't there first.
I dont want to create it but to check its existence. is this some other problem?
Open it in binary mode :
open(str(path), 'rb')